Submission #232184

# Submission time Handle Problem Language Result Execution time Memory
232184 2020-05-16T10:43:12 Z VEGAnn XOR Sum (info1cup17_xorsum) C++14
77 / 100
1600 ms 24056 KB
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("no-stack-protector")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define sz(x) int(x.size())
#define all(x) x.begin(),x.end()
#define PB push_back
#define MP make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pil pair<int, ll>
#define pli pair<ll, int>
#define pdd pair<ld, ld>
#define ft first
#define sd second
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
template<class T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const int N = 1000100;
const int M = 100100;
const int BIG = int(5e6);
const int oo = 2e9;
const ll OO = 1e18;
const int md = 998244353;
const int PW = 30;
const int MASK = (1 << 15) - 1;
ll sum;
int a[N], ans = 0, n, mask, mn, mx, l1, r1, l2, r2, vc[N], pref, nw_pref;
int b[2][N][2], kol[MASK + 1];

int main() {
#ifdef _LOCAL
    freopen("in.txt","r",stdin); //freopen("output.txt","w",stdout);
#else
//    freopen("mining.in","r",stdin); freopen("mining.out","w",stdout);
    ios_base::sync_with_stdio(0); cin.tie(0);
#endif

    cin >> n;

    for (int i = 0; i < n; i++)
        cin >> a[i];

    for (int bt = 0; bt < PW; bt++){

        mask = (1 << (bt + 1)) - 1;

        for (int i = 0; i < n; i++) {
            vc[i] = a[i] & mask;
            b[0][i][0] = (vc[i] & MASK);
            b[1][i][0] = (vc[i] >> 15);
        }

        for (int it = 0; it < 2; it++){
            for (int i = 0; i <= MASK; i++)
                kol[i] = 0;

            for (int i = 0; i < n; i++)
                kol[b[it][i][it]]++;

            pref = nw_pref = 0;

            for (int i = 0; i <= MASK; i++){
                nw_pref += kol[i];
                kol[i] = pref;
                pref = nw_pref;
            }

            for (int i = 0; i < n; i++){
                int ps = kol[b[it][i][it]]++;

                b[0][ps][it ^ 1] = b[0][i][it];
                b[1][ps][it ^ 1] = b[1][i][it];
            }
        }

        for (int i = 0; i < n; i++)
            vc[i] = b[0][i][0] + (b[1][i][0] << 15);

        sum = 0;

        l1 = n, r1 = n - 1, l2 = n, r2 = n - 1;

        for (int i = 0; i < n; i++){
            int &cr = vc[i];

            mn = (1 << bt) - cr;
            mx = (1 << (bt + 1)) - 1 - cr;

            while (l1 > 0 && vc[l1 - 1] >= mn)
                l1--;

            while (r1 >= 0 && vc[r1] > mx)
                r1--;

            sum += r1 - l1 + 1;

            if (cr >= mn && cr <= mx)
                sum--;

            mn += (1 << (bt + 1));
            mx = (1 << (bt + 2)) - 1 - cr;

            while (l2 > 0 && vc[l2 - 1] >= mn)
                l2--;

            while (r2 >= 0 && vc[r2] > mx)
                r2--;

            sum += r2 - l2 + 1;

            if (cr >= mn && cr <= mx)
                sum--;
        }

        sum /= 2;

        if (sum & 1)
            ans += (1 << bt);
    }

    for (int i = 0; i < n; i++)
        ans ^= (a[i] + a[i]);

    cout << ans;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 12 ms 640 KB Output is correct
2 Correct 13 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1151 ms 24004 KB Output is correct
2 Correct 1069 ms 22520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1151 ms 24004 KB Output is correct
2 Correct 1069 ms 22520 KB Output is correct
3 Correct 1328 ms 24056 KB Output is correct
4 Correct 1274 ms 23164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 640 KB Output is correct
2 Correct 13 ms 768 KB Output is correct
3 Correct 151 ms 2936 KB Output is correct
4 Correct 152 ms 2816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 640 KB Output is correct
2 Correct 13 ms 768 KB Output is correct
3 Correct 1151 ms 24004 KB Output is correct
4 Correct 1069 ms 22520 KB Output is correct
5 Correct 1328 ms 24056 KB Output is correct
6 Correct 1274 ms 23164 KB Output is correct
7 Correct 151 ms 2936 KB Output is correct
8 Correct 152 ms 2816 KB Output is correct
9 Execution timed out 1643 ms 24056 KB Time limit exceeded
10 Halted 0 ms 0 KB -