답안 #202263

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
202263 2020-02-14T17:18:35 Z Bagritsevich_Stepan XOR Sum (info1cup17_xorsum) C++14
100 / 100
908 ms 35320 KB
//#include "/Users/stdc++.h"
#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pii pair < int, int >
#define fs first
#define sc second
#define getfiles ifstream cin("input.txt"); ofstream cout("output.txt");
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

typedef long long ll;
typedef long double ld;

const int INF = 2e9;
const ll BIG_INF = 1e18;
const ll MOD = 1e9 + 7;

const int maxn = 1e6 + 5;
pii x[maxn], for_sort[2][maxn];
int n, a[maxn], sz[2], bit;

bool get_bit(int x, int k) {
    return x & (1 << k);
}

void Sort() {
    for (int i = 0; i < n; i++)
        if (get_bit(a[x[i].sc], bit))
            x[i].fs |= 1 << bit;
    
    sz[0] = sz[1] = 0;
    for (int i = 0; i < n; i++) {
        int ind = get_bit(x[i].fs, bit);
        for_sort[ind][sz[ind]++] = x[i];
    }
    
    int ind = 0;
    for (int i = 0; i < 2; i++)
        for (int j = 0; j < sz[i]; j++)
            x[ind++] = for_sort[i][j];
}

int main() {
    fast_io
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        x[i].sc = i;
    }
    
    int ans = 0;
    for (bit = 0; bit < 30; bit++) {
        Sort();
        
        int val = 1 << bit, p1 = n, p2 = n, p3 = n;
        for (int i = 0; i < n; i++) {
            if (p1 < i) p1 = i;
            while (i < p1 && x[i].fs + x[p1 - 1].fs >= val)
                p1--;
            
            if (p2 < i) p2 = i;
            while (i < p2 && x[i].fs + x[p2 - 1].fs >= 2 * val)
                p2--;
            
            if (p3 < i) p3 = i;
            while (i < p3 && x[i].fs + x[p3 - 1].fs >= 3 * val)
                p3--;
            
            if ((p2 - p1 + n - p3) % 2)
                ans ^= (1 << bit);
        }
    }
    
    cout << ans << "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 376 KB Output is correct
2 Correct 8 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 629 ms 25864 KB Output is correct
2 Correct 596 ms 24288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 629 ms 25864 KB Output is correct
2 Correct 596 ms 24288 KB Output is correct
3 Correct 734 ms 25848 KB Output is correct
4 Correct 723 ms 31352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 376 KB Output is correct
2 Correct 8 ms 504 KB Output is correct
3 Correct 96 ms 3080 KB Output is correct
4 Correct 93 ms 2940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 376 KB Output is correct
2 Correct 8 ms 504 KB Output is correct
3 Correct 629 ms 25864 KB Output is correct
4 Correct 596 ms 24288 KB Output is correct
5 Correct 734 ms 25848 KB Output is correct
6 Correct 723 ms 31352 KB Output is correct
7 Correct 96 ms 3080 KB Output is correct
8 Correct 93 ms 2940 KB Output is correct
9 Correct 898 ms 35320 KB Output is correct
10 Correct 908 ms 35188 KB Output is correct
11 Correct 899 ms 35192 KB Output is correct