답안 #197210

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
197210 2020-01-19T16:40:25 Z Pankin XOR Sum (info1cup17_xorsum) C++14
56 / 100
1600 ms 15408 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("-O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define mp make_pair
#define ll long long
#define ld long double
#define pb push_back
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fs first
#define sc second
#define getfiles ifstream cin("input.txt"); ofstream cout("output.txt");
#define endl '\n'
#define pii pair<int, int>

const int INF = 2000000005;
const ll BIG_INF = 2000000000000000005;
const int mod = 1000000007;
const int P = 31;
const ld PI = 3.141592653589793238462643;
const double eps = 1e-9;

using namespace std;
using namespace __gnu_pbds;

bool valid(int x, int y, int n, int m) {
    return x >= 0 && y >= 0 && x < n && y < m;
}

mt19937 rng(1999999973);

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int N = 1000000 + 5;
int order[N], p[2][N], o[2], a[N], n, ans = 0;

inline int readint() {
    int x = 0;
    char ch = getchar_unlocked();
    while (ch < '0' || ch > '9') {
        ch = getchar_unlocked();
    }
    while (ch >= '0' && ch <= '9') {
        x = (x << 3) + (x << 1) + ch - '0';
        ch = getchar_unlocked();
    }
    return x;
}

signed main() {
    fast_io;

    n = readint();
    for (int i = 0; i < n; i++) {
        a[i] = readint();
        order[i] = i;
    }

    int curmask = 0;
    int pointer[2] = {o[0], o[1]}, same = 0, col = 0;
    for (int bit = 0; bit < 29; bit++) {
        o[0] = o[1] = 0;

        for (int i = 0; i < n; i++) {
            int v = (a[order[i]]>>bit)&1;
            p[v][o[v]] = order[i];
            o[v]++;
        }

        pointer[0] = o[0], pointer[1] = o[1], same = 0, col = 0;
        for (int i = 0; i < n; i++) {
            for (int bt = 0; bt < 2; bt++) {
                while(pointer[bt] > 0 && (a[p[bt][pointer[bt] - 1]]&curmask) + (a[order[i]]&curmask) >= (1 << bit))
                    pointer[bt]--;

                if (((a[order[i]]>>bit)&1) != bt)
                    col += pointer[bt];
                else
                    col += o[bt] - pointer[bt];
            }

            if (((a[order[i]] + a[order[i]])>>bit)&1)
                same++;
            col &= 3;
        }
        col += 4 - (same&3);
        col >>= 1;
        col += same;

        ans |= ((col&1) << bit);

        int cur = 0;
        for (int bt = 0; bt < 2; bt++) {
            for (int i = 0; i < o[bt]; i++) {
                order[cur] = p[bt][i];
                cur++;
            }
        }

        curmask <<= 1;
        curmask++;
    }

    cout << ans;

    return 0;
}

/*
2
7 0
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 504 KB Output is correct
2 Correct 6 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1589 ms 15024 KB Output is correct
2 Correct 1401 ms 14412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1589 ms 15024 KB Output is correct
2 Correct 1401 ms 14412 KB Output is correct
3 Execution timed out 1633 ms 15408 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 504 KB Output is correct
2 Correct 6 ms 504 KB Output is correct
3 Correct 145 ms 1784 KB Output is correct
4 Correct 149 ms 1784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 504 KB Output is correct
2 Correct 6 ms 504 KB Output is correct
3 Correct 1589 ms 15024 KB Output is correct
4 Correct 1401 ms 14412 KB Output is correct
5 Execution timed out 1633 ms 15408 KB Time limit exceeded
6 Halted 0 ms 0 KB -