답안 #197213

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
197213 2020-01-19T16:42:45 Z Pankin XOR Sum (info1cup17_xorsum) C++14
77 / 100
1600 ms 23004 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();
    while (ch < '0' || ch > '9') {
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = (x << 3) + (x << 1) + ch - '0';
        ch = getchar();
    }
    return x;
}

signed main() {
    fast_io;

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

    if (mx <= 1000000)
        mx = 21;
    else
        mx = 29;

    int curmask = 0;
    int pointer[2] = {o[0], o[1]}, same = 0, col = 0;
    for (int bit = 0; bit < mx; 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 6 ms 504 KB Output is correct
2 Correct 6 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1143 ms 15084 KB Output is correct
2 Correct 951 ms 14080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1143 ms 15084 KB Output is correct
2 Correct 951 ms 14080 KB Output is correct
3 Correct 1456 ms 15016 KB Output is correct
4 Correct 1210 ms 14580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 504 KB Output is correct
2 Correct 6 ms 504 KB Output is correct
3 Correct 149 ms 1784 KB Output is correct
4 Correct 163 ms 1784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 504 KB Output is correct
2 Correct 6 ms 504 KB Output is correct
3 Correct 1143 ms 15084 KB Output is correct
4 Correct 951 ms 14080 KB Output is correct
5 Correct 1456 ms 15016 KB Output is correct
6 Correct 1210 ms 14580 KB Output is correct
7 Correct 149 ms 1784 KB Output is correct
8 Correct 163 ms 1784 KB Output is correct
9 Execution timed out 1698 ms 23004 KB Time limit exceeded
10 Halted 0 ms 0 KB -