Codeforces Round #731 (Div. 3) D. Co-growing Sequence(位运算/贪心)

include <bits/stdc++.h>

using namespace std;
int n;
int x[200005], y[200005], xr[200005];
int main() {
int t;
cin >> t;
while(t--) {
cin >> n;
for(int i = 1; i <= n; i++) cin >> x[i];
for(int i = 1; i <= n; i++) {
int tmp = 0;
if(i == 1) {
y[1] = 0;
xr[1] = 0 ^ x[1];
continue;
}
int fuck = 0;
for(int j = 0; j < 32; j++) {//逐位分析
fuck |= (((xr[i - 1] >> j) & 1) << j);
if((xr[i - 1] >> j) & 1) {//由题目要求
if((x[i] >> j) & 1) {
tmp |= (0 << j);
} else {
tmp |= (1 << j);
}
} else {
if(fuck == xr[i - 1]) {//如果已经遍历完xr[i - 1]的有效位 那么y[i]剩下全取0即可,直接break
break;
} else {

				}
			}
		}
		y[i] = tmp;
		xr[i] = x[i] ^ y[i];//不要忘记更新
	}
	for(int i = 1; i <= n; i++) {
		cout << y[i] << " ";
	}
	cout << endl;
}
return 0;

}

Codeforces Round #731 (Div. 3) D. Co-growing Sequence(位运算/贪心)

上一篇:(先导)Git Api对接:获取private_token的两种方式


下一篇:vue(33)vue中CompositionAPI中setup响应式变量的声明