답안 #1092509

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1092509 2024-09-24T08:59:04 Z pubin06 XOR Sum (info1cup17_xorsum) C++14
100 / 100
751 ms 32468 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;
int a[MXn];
int 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;
    vector<int> v[2];
    v[0].resize(N);
    iota(begin(v[0]), end(v[0]), 1);
    for (int k = 0; k < 30; k++) {
    	mask |= (1 << k);
    	int num = 0;
    	vector<int> tmp[2];
    	for (int id: v[0]) if ((a[id] >> k) % 2 == 0) {
    		tmp[0].emplace_back(id);
    		t[++num] = (a[id] & mask);
    	}
    	for (int id: v[1]) if ((a[id] >> k) % 2 == 0) {
    		tmp[0].emplace_back(id);
    		t[++num] = (a[id] & mask);
    	}
    	for (int id: v[0]) if ((a[id] >> k) & 1) {
    		tmp[1].emplace_back(id);
    		t[++num] = (a[id] & mask);
    	}
    	for (int id: v[1]) if ((a[id] >> k) & 1) {
    		tmp[1].emplace_back(id);
    		t[++num] = (a[id] & mask);
    	}
    	v[0] = tmp[0];
    	v[1] = tmp[1];
    	int p1 = N, p2 = N, p3 = N;
    	int cnt = 0;
    	for (int i = 1; i <= N; i++) {
    		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 += (max(p2, i - 1) - max(p1, i - 1)) + (N - max(i, p3 + 1) + 1);
    		cnt &= 1;
    	}
    	ans += (cnt << k);
    }
    cout << ans;
    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 604 KB Output is correct
2 Correct 3 ms 524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 465 ms 27784 KB Output is correct
2 Correct 418 ms 26204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 465 ms 27784 KB Output is correct
2 Correct 418 ms 26204 KB Output is correct
3 Correct 562 ms 29896 KB Output is correct
4 Correct 544 ms 29004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 604 KB Output is correct
2 Correct 3 ms 524 KB Output is correct
3 Correct 70 ms 3584 KB Output is correct
4 Correct 75 ms 3584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 604 KB Output is correct
2 Correct 3 ms 524 KB Output is correct
3 Correct 465 ms 27784 KB Output is correct
4 Correct 418 ms 26204 KB Output is correct
5 Correct 562 ms 29896 KB Output is correct
6 Correct 544 ms 29004 KB Output is correct
7 Correct 70 ms 3584 KB Output is correct
8 Correct 75 ms 3584 KB Output is correct
9 Correct 721 ms 32444 KB Output is correct
10 Correct 723 ms 32436 KB Output is correct
11 Correct 751 ms 32468 KB Output is correct