Submission #919103

# Submission time Handle Problem Language Result Execution time Memory
919103 2024-01-31T09:27:31 Z Pragmatism XOR Sum (info1cup17_xorsum) C++17
45 / 100
90 ms 6172 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 = 4e5 + 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 600 KB Output is correct
2 Correct 4 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 5456 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 5456 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 600 KB Output is correct
2 Correct 4 ms 600 KB Output is correct
3 Correct 87 ms 6172 KB Output is correct
4 Correct 90 ms 6068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 600 KB Output is correct
2 Correct 4 ms 600 KB Output is correct
3 Incorrect 23 ms 5456 KB Output isn't correct
4 Halted 0 ms 0 KB -