답안 #202258

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
202258 2020-02-14T15:39:48 Z Bagritsevich_Stepan XOR Sum (info1cup17_xorsum) C++14
45 / 100
1600 ms 22048 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;
int n, a[maxn], inds[maxn], bit;
vector < int > for_sort[2];

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

void Sort() {
    for (int i = 0; i < n; i++) {
        int ind = inds[i];
        for_sort[get_bit(a[ind], bit)].pb(ind);
    }
    
    int ind = 0;
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < sz(for_sort[i]); j++)
            inds[ind++] = for_sort[i][j];
        for_sort[i].clear();
    }
}

int get_val(int i, int j) {
    int x = a[inds[i]] % (1 << (bit + 1));
    int y = a[inds[j]] % (1 << (bit + 1));
    return x + y;
}

void upd_p(int &p, int i, int add) {
    if (p < i) p = i;
    
    while (i < p && get_val(i, p - 1) >= add * (1 << bit))
        p--;
}

int main() {
    fast_io
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        inds[i] = i;
    }
    
    int ans = 0;
    for (bit = 0; bit < 30; bit++) {
        Sort();
        
        int p1 = n, p2 = n, p3 = n;
        for (int i = 0; i < n; i++) {
            upd_p(p1, i, 1);
            upd_p(p2, i, 2);
            upd_p(p3, i, 3);
            
            int cnt_ones = p2 - p1 + n - p3;
            if (cnt_ones % 2) ans ^= (1 << bit);
        }
    }
    
    cout << ans << "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 504 KB Output is correct
2 Correct 13 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1616 ms 22048 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1616 ms 22048 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 504 KB Output is correct
2 Correct 13 ms 376 KB Output is correct
3 Correct 231 ms 3316 KB Output is correct
4 Correct 227 ms 3188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 504 KB Output is correct
2 Correct 13 ms 376 KB Output is correct
3 Execution timed out 1616 ms 22048 KB Time limit exceeded
4 Halted 0 ms 0 KB -