답안 #1092479

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1092479 2024-09-24T07:54:18 Z pubin06 XOR Sum (info1cup17_xorsum) C++14
45 / 100
1600 ms 12664 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define sz(v) (int)(v).size()
using namespace std;

const int MXn = 1000005;
const long long oo = 1e18;
const int MOD = 1e9 + 7;

int N, a[MXn], t[MXn];

signed main(void) {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    
    cin >> N;
    for (int i = 1; i <= N; i++) cin >> a[i];
    int mask = 0;
    int ans = 0;
    for (int k = 0; k < 30; k++) {
    	mask |= (1 << k);
    	for (int i = 1; i <= N; i++) t[i] = a[i] & mask;
    	sort(t + 1, t + 1 + N);
    	int p1 = N, p2 = N, p3 = N;
    	int cnt = 0;
    	// [2^k, 2^(k+1) - 1]; [2^(k+1) + 2^k, 2^(k+2) - 2]
    	// cerr << (1 << k) << ' ' << ((1 << (k + 1)) - 1) << ' ' << ((1 << (k + 1)) + (1 << k)) << ' ' << ((1 << (k + 2)) - 2) << ' ';
    	// cerr << "[ ";
    	// for (int i = 1; i <= N; i++) {
    		// cerr << t[i] << ' ';
    	// }
    	// cerr << "] ";
    	for (int i = 1; i <= N; i++) {
    		p1 = lower_bound(t + i, t + 1 + N, (1 << k) - t[i]) - t;
    		p2 = lower_bound(t + i, t + 1 + N, (1 << (k + 1)) - t[i]) - t;
    		p3 = lower_bound(t + i, t + 1 + N, (1 << (k + 1)) + (1 << k) - t[i]) - t;
    		// while (t[i] + t[p1] > (1 << k) && p1 >= i) p1--;
    		// while (t[i] + t[p2] >= (1 << (k + 1)) && p2 >= i) p2--;
    		// while (t[i] + t[p3] >= ((1 << (k + 1)) + (1 << k)) && p3 >= i) p3--;
    		cnt += (p2 - p1) + (N - max(i, p3 + 1) + 1);
    		// cerr << "(" << p1 << ' ' << p2 << ' ' << p3 << ")";
    		// cnt &= 1;
    	}
    	// cerr << ' ' << cnt << '\n';
    	
    	cnt &= 1;
    	ans += (cnt << k);
    }
    cout << ans;
    
    return 0;
}
/*
00011
01001
00110
00110
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 348 KB Output is correct
2 Correct 11 ms 540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1651 ms 12664 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1651 ms 12664 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 348 KB Output is correct
2 Correct 11 ms 540 KB Output is correct
3 Correct 319 ms 2136 KB Output is correct
4 Correct 344 ms 2140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 348 KB Output is correct
2 Correct 11 ms 540 KB Output is correct
3 Execution timed out 1651 ms 12664 KB Time limit exceeded
4 Halted 0 ms 0 KB -