Bored, send a version bit computing solution to a problem, nay sayers
Subject to the effect
A given sequence \ (A \) , each operation can be added at any element \ (2 \) , and asked whether the final all such elements are equal.
analysis
You can find the maximum value \ (- \) current location, if an even number, then another to understand what is the same parity of all the elements, you can maintain a \ (and \) and, as well as a \ (or \) and, finally see the binary the last one just fine.
Code
#include<bits/stdc++.h>
#define REP(i,first,last) for(int i=first;i<=last;++i)
#define DOW(i,first,last) for(int i=first;i>=last;--i)
using namespace std;
int T,N;
void YES()
{
printf("YES\n");
}
void NO()
{
printf("NO\n");
}
void work()
{
scanf("%d",&N);
int and_=1,or_=0;//记录and和以及or和,初值为1和0
int a;
REP(i,1,N)
{
scanf("%d",&a);
and_&=a&1;//因为用到的知识奇偶性所以可以直接在a上and1
or_|=a&1;
}
if(and_||or_^1)//如果and最后为1(全是奇数),或者or最后为0(全是偶数),则输出YES
{
YES();
return;
}
NO();//否则不成立
}
int main()
{
scanf("%d",&T);
REP(i,1,T)
{
work();
}
return 0;
}