답안 #129290

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
129290 2019-07-12T02:15:49 Z TAISA_ XOR Sum (info1cup17_xorsum) C++14
0 / 100
1600 ms 38428 KB
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using P=pair<int,int>;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	int n;cin>>n;
	vector<ll> a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	vector<int> co(30);
	vector<int> v(n),id(n);
	for(int i=0;i<n;i++){
		id[i]=i;
	}
	for(int k=0;k<30;k++){
		int j=n-1;
		vector<int> v0,v1,s(n+1),vi0,vi1;
		for(int i=1;i<=n;i++){
			s[i]=s[i-1]+((a[id[i-1]]>>k)&1);
		}
		for(int i=0;i<n;i++){
			while(j>=0&&(1<<k)-v[i]<=v[j])--j;
			if((a[id[i]]>>k)&1){
				co[k]+=s[j+1];
				co[k]+=(n-1-j)-(s[n]-s[j+1]);
				v1.push_back((1<<k)+v[i]);
				vi1.push_back(id[i]);
			}else{
				co[k]+=s[n]-s[j+1];
				co[k]+=j+1-s[j+1];
				v0.push_back(v[i]);
				vi0.push_back(id[i]);
			}
			co[k]&=1;
		}
		for(int i=0;i<v0.size();i++){
			v[i]=v0[i];
			id[i]=vi0[i];
		}
		for(int i=0;i<v1.size();i++){
			v[i+v0.size()]=v1[i];
			id[i+v0.size()]=vi1[i];
		}
	}
	int ans=0;
	for(int k=0;k<30;k++){
		if(co[k]){
			ans^=(1<<k);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Compilation message

xorsum.cpp: In function 'int main()':
xorsum.cpp:39:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<v0.size();i++){
               ~^~~~~~~~~~
xorsum.cpp:43:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<v1.size();i++){
               ~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1671 ms 38428 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1671 ms 38428 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -