35求助
  • 板块P9227 异或积
  • 楼主rnf5114
  • 当前回复2
  • 已保存回复2
  • 发布时间2023/4/22 21:03
  • 上次更新2023/10/23 17:45:24
查看原帖
35求助
917683
rnf5114楼主2023/4/22 21:03
#include <bits/stdc++.h>
using namespace std;
long long n,k,t,a[200010],b[200010]={};
int main(){
	cin>>t;
	for(int i=1;i<=t;i++){
		cin>>n>>k;
		memset(b,0,sizeof(b));
		for(int j=1;j<=n;j++){
			cin>>a[j];
		}
		if(n%2){
			for(int j=1;j<=n;j++){
				for(int q=1;q<=n;q++){
					if(q!=j){
						b[j]=b[j]^a[q];	
					}
				}
			}
			for(int j=1;j<=n;j++){
				cout<<b[j]<<" ";
			}
			cout<<endl;
		}
		else{
			if(k%2){
				for(int j=1;j<=n;j++){
					for(int q=1;q<=n;q++){
						if(q!=j){
							b[j]=b[j]^a[q];	
						}
					}
				}
				for(int j=1;j<=n;j++){
					cout<<b[j]<<" ";
				}
				cout<<endl;
			}
			else{
				for(int j=1;j<=n;j++){
					cout<<a[j]<<" ";
				}
				cout<<endl;
			}
		}
	}
    return 0;
}
2023/4/22 21:03
加载中...