답안 #68029

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
68029 2018-08-15T19:27:47 Z top34051 XOR Sum (info1cup17_xorsum) C++17
45 / 100
1600 ms 15676 KB
#include<bits/stdc++.h>
using namespace std;

const int maxn = 1e6 + 5;
const int mlog = 28;

int n;
int a[maxn];

int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);

	int ans = 0;

	for(int i=0;i<=mlog;i++) {
		int pw = (1<<i);

//		printf("pw = %d\n",pw);

		vector<int> b[2];
		for(int x=1;x<=n;x++) {
//            printf("\ti = %d  %d\n",a[x],(a[x]/pw)%2);
            b[(a[x]/pw)%2].push_back(a[x]%pw);
		}
		sort(b[0].begin(),b[0].end()); int sz0 = b[0].size();
		sort(b[1].begin(),b[1].end()); int sz1 = b[1].size();

//        printf("\t");
//		for(auto t : b[0]) printf("%d ",t);
//		printf("\n");
//        printf("\t");
//		for(auto t : b[1]) printf("%d ",t);
//		printf("\n");

		int cnt1 = 0, cnt2 = 0, cnt3 = 0;

		//tx = 0 ty = 0
		//2^i <= b[x] + b[y] (< 2^(i+1))
		for(int x=0,y=sz0;x<sz0;x++) {
			while(y-1 >= 0 && pw <= b[0][x] + b[0][y-1]) y--;
			cnt1 += sz0-y;
		}
		for(auto t : b[0]) if(pw <= t*2) cnt1++;
		cnt1 /= 2;

		//tx = 0 ty = 1
		//b[x] + b[y] < 2^i
		for(int x=sz0-1,y=-1;x>=0;x--) {
			while(y+1 < sz1 && b[0][x] + b[1][y+1] < pw) y++;
			cnt2 += y+1;
		}

		//tx = 1 ty = 1
		//2^i <= b[x] + b[y] (< 2^(i+1))
		for(int x=0,y=sz1;x<sz1;x++) {
			while(y-1 >= 0 && pw <= b[1][x] + b[1][y-1]) y--;
			cnt3 += sz1-y;
		}
		for(auto t : b[1]) if(pw <= t*2) cnt3++;
		cnt3 /= 2;

		if((cnt1+cnt2+cnt3)&1) ans += pw;
	}

	printf("%d",ans);
}

Compilation message

xorsum.cpp: In function 'int main()':
xorsum.cpp:11:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
xorsum.cpp:12:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1;i<=n;i++) scanf("%d",&a[i]);
                        ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 396 KB Output is correct
2 Correct 12 ms 528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1673 ms 15676 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1673 ms 15676 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 396 KB Output is correct
2 Correct 12 ms 528 KB Output is correct
3 Correct 289 ms 15676 KB Output is correct
4 Correct 268 ms 15676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 396 KB Output is correct
2 Correct 12 ms 528 KB Output is correct
3 Execution timed out 1673 ms 15676 KB Time limit exceeded
4 Halted 0 ms 0 KB -