답안 #129321

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
129321 2019-07-12T03:00:09 Z TAISA_ XOR Sum (info1cup17_xorsum) C++14
100 / 100
1514 ms 37136 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),vv(n),idd(n);
	for(int i=0;i<n;i++){
		id[i]=i;
	}
	vector<int> s(n+1);
	for(int k=0;k<30;k++){
		int j=n-1;
		for(int i=1;i<=n;i++){
			s[i]=s[i-1]+((a[id[i-1]]>>k)&1);
		}
		int sum=n-s[n];
		int id0=0,id1=0;
		for(int i=0;i<n;i++){
			while(j>=0&&(1<<k)-v[i]<=v[j])--j;
			if((a[id[i]]>>k)&1){
				if(i>j)co[k]+=s[i+1]-s[j+1];
				co[k]+=min(i+1,j+1)-s[min(i+1,j+1)];
				vv[sum+id1]=(1<<k)+v[i];
				idd[sum+id1]=id[i];
				id1++;
			}else{
				if(i>j)co[k]+=(i-j)-(s[i+1]-s[j+1]);
				co[k]+=s[min(i+1,j+1)];
				vv[id0]=v[i];
				idd[id0]=id[i];
				id0++;
			}
			co[k]&=1;
		}
		swap(v,vv);
		swap(id,idd);
	}
	int ans=0;
	for(int k=0;k<30;k++){
		if(co[k]){
			ans^=(1<<k);
		}
	}
	cout<<ans<<endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1166 ms 27892 KB Output is correct
2 Correct 1095 ms 30328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1166 ms 27892 KB Output is correct
2 Correct 1095 ms 30328 KB Output is correct
3 Correct 1235 ms 34580 KB Output is correct
4 Correct 1193 ms 33400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 93 ms 3172 KB Output is correct
4 Correct 93 ms 3140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 1166 ms 27892 KB Output is correct
4 Correct 1095 ms 30328 KB Output is correct
5 Correct 1235 ms 34580 KB Output is correct
6 Correct 1193 ms 33400 KB Output is correct
7 Correct 93 ms 3172 KB Output is correct
8 Correct 93 ms 3140 KB Output is correct
9 Correct 1373 ms 37136 KB Output is correct
10 Correct 1514 ms 37112 KB Output is correct
11 Correct 1363 ms 37112 KB Output is correct