답안 #162218

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
162218 2019-11-07T07:15:59 Z mrtsima22 XOR Sum (info1cup17_xorsum) C++17
56 / 100
1600 ms 51028 KB
#pragma GCC optimize "-O3"
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define two pair<int,int>
#define pb push_back
#define f first
#define s second
#define sz(container) (int)(container.size())
using namespace std;
inline int bin(){
	int x=0;char ch=getchar();
	while (ch<'0'||ch>'9') ch=getchar();
	while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return x;
}
const int M=29;
two a[1000004],b[1000004];
int c[39],ans,n,d[39];
inline void work(int x,int y,int &k,int &K){
	int l=-1,r=-1;
	for(int o=n-1;o>=0;o--){
		while(l+1<n&&b[l+1].f+b[o].f<x) l++;
		while(r+1<n&&b[r+1].f+b[o].f<=y) r++;
		if(o>l&&o<=r) K++;
		if(l<=r)
			k+=(r-l);
	}
}
int main(){
for(int i=1;i<=M;i++){
	c[i]=(1<<(i+1))-1;
	d[i]=(1<<(i));
}
n=bin();
for(int i=0;i<n;i++){
	a[i].f=bin();
	a[i].s=i;
}
for(int i=1;i<=M;i++){
	if(i==1){	
		for(int j=0;j<n;j++){
			b[j].f=c[i]&a[j].f;
			b[j].s=a[j].s;
		}
		sort(b,b+n);
	}else{
		for(int j=0;j<n;j++){
			b[j].f=b[j].f&c[i];
		}
		vector<two>v0,v1,v;
		for(int j=0;j<n;j++){
			if(d[i]&b[j].f){
				v1.pb(b[j]);
			}else{
				v0.pb(b[j]);
			}
		}
		for(int j=0;j<sz(v0);j++){
			v.pb(v0[j]);
		}
		for(int j=0;j<sz(v1);j++){
			v.pb(v1[j]);
		}
		for(int j=0;j<sz(v);j++){
			b[j]=v[j];
		}
	}	
	int b1=(1<<(i));
	int b2=((1<<(i+1))-1);
	int B1=b1+(1<<(i+1));
	int B2=((1<<(i+2))-2);
	int k=0,K=0;
	work(b1,b2,k,K);
	work(B1,B2,k,K);
	k-=K;
	k/=2;
	k+=K;
	if(k&1){
		ans|=(1<<(i));
	}
	for(int j=0;j<n;j++){
		b[j].f=a[b[j].s].f;
	}
}
int k=0;
for(int i=0;i<n;i++){
	if(a[i].f&1) k++;
}
if((k*(n-k))&1){
	ans++;
}
cout<<ans<<endl;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 504 KB Output is correct
2 Correct 8 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1505 ms 45976 KB Output is correct
2 Correct 1403 ms 43680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1505 ms 45976 KB Output is correct
2 Correct 1403 ms 43680 KB Output is correct
3 Execution timed out 1626 ms 51028 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 504 KB Output is correct
2 Correct 8 ms 504 KB Output is correct
3 Correct 171 ms 5976 KB Output is correct
4 Correct 173 ms 5896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 504 KB Output is correct
2 Correct 8 ms 504 KB Output is correct
3 Correct 1505 ms 45976 KB Output is correct
4 Correct 1403 ms 43680 KB Output is correct
5 Execution timed out 1626 ms 51028 KB Time limit exceeded
6 Halted 0 ms 0 KB -