Submission #919104

# Submission time Handle Problem Language Result Execution time Memory
919104 2024-01-31T09:27:57 Z Pragmatism XOR Sum (info1cup17_xorsum) C++17
100 / 100
856 ms 43380 KB
//Bismillahir-Rahmanir-Rahim

#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")
#pragma GCC target("sse,sse2,sse3,sse4,sse4.1,sse4.2,popcnt,avx,avx2")

#define pb push_back
#define pii pair <int, int>
#define pll pair <long long, long long>
#define pld pair <long double, long double>
#define ll long long
#define ld long double
#define x first
#define y second
#define all(v) v.begin(),v.end()
#define sz(s) (int)s.size()
#define skip continue
#define bpop(x) (ll)__builtin_popcountll(x)

using namespace std;

const int N = 1e6 + 7;
const int K = 150;
const int SQRT = 2100;
const int maxA = 1e6 + 7;
const int inf = 1e9 + 7;
const ll INF = 1e18 + 7;
const int MOD = 1e9 + 7;
const ld eps = 1e-9;

pii dir[] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define int long long

int n, a[N];
int f(int l, int r) {
	int j = 0, k = 0, cur = 0;
	for (int i = n;i >= 1;i--) {
	    while (k < n && a[k + 1] <= r - a[i])k++;
	    while (j < n && a[j + 1] < l - a[i])j++;
		cur += min(i, k) - min(i, j);
	}
	return cur;
}
void solve() {
    cin >> n;
    for (int i = 1;i <= n;i++)cin >> a[i];
    int ans = 0;
    sort(a + 1, a + n + 1);
    for (int bit = 30;bit >= 0;bit--) {
        //sort(a + 1, a + n + 1);
        int cnt = f((1ll << bit), (1ll << (bit + 1)) - 1) + f((1ll << (bit + 1)) + (1ll << bit), INF);
        ans += (cnt % 2) * (1ll << bit);
        vector <int> zero, one, res(n);
        for (int i = 1;i <= n;i++) {
            bool type = ((a[i] >> bit) & 1);
            if (type)a[i] -= (1ll << bit), one.pb(a[i]);
            else zero.pb(a[i]);
        }
        merge(all(zero), all(one), res.begin());
        for (int i = 1;i <= n;i++)a[i] = res[i - 1];
    }
    cout << ans;
}
signed main() {
    //srand(time(NULL));
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("tests.in", "r", stdin);
    //freopen("milkorder.out", "w", stdout);
    int test = 1;
    //cin >> test;
    for (int t = 1;t <= test;t++) {
        //cout << "Case " << t << ": ";
        solve();
    }
    return 0;
}

Compilation message

xorsum.cpp:4: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]
    4 | #pragma comment(linker, "/stack:200000000")
      |
# Verdict Execution time Memory Grader output
1 Correct 4 ms 348 KB Output is correct
2 Correct 4 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 529 ms 35172 KB Output is correct
2 Correct 487 ms 35572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 529 ms 35172 KB Output is correct
2 Correct 487 ms 35572 KB Output is correct
3 Correct 637 ms 39916 KB Output is correct
4 Correct 614 ms 39776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 348 KB Output is correct
2 Correct 4 ms 348 KB Output is correct
3 Correct 87 ms 5300 KB Output is correct
4 Correct 90 ms 5152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 348 KB Output is correct
2 Correct 4 ms 348 KB Output is correct
3 Correct 529 ms 35172 KB Output is correct
4 Correct 487 ms 35572 KB Output is correct
5 Correct 637 ms 39916 KB Output is correct
6 Correct 614 ms 39776 KB Output is correct
7 Correct 87 ms 5300 KB Output is correct
8 Correct 90 ms 5152 KB Output is correct
9 Correct 856 ms 41920 KB Output is correct
10 Correct 831 ms 43380 KB Output is correct
11 Correct 830 ms 42664 KB Output is correct