Submission #1098061

# Submission time Handle Problem Language Result Execution time Memory
1098061 2024-10-09T02:24:03 Z thangdz2k7 XOR Sum (info1cup17_xorsum) C++17
100 / 100
636 ms 21740 KB
// author : thembululquaUwU
// 3.9.2024

#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define endl '\n'

using namespace std;
using ll = long long;
using ii = pair <int, int>;
using vi = vector <int>;

const int MaxN = 1e6 + 5;
const int mod = 1e9 + 7;
const int LG = 30;

void maxl(auto &a, auto b) {a = max(a, b);}
void minl(auto &a, auto b) {a = min(a, b);}

#define Mask(i)  (1 << (i))
#define Bit(x, i)  ((x) >> (i) & 1)
#define bp __builtin_popcount
#define bpll __builtin_popcountll

void solve(){
    int n; cin >> n; int ans = 0;
    vi a(n); for (int i = 0; i < n; ++ i) cin >> a[i];
    for (int b = 0; b < LG; ++ b){
        vi t; int mx = Mask(b + 1) - 1;
        for (int i = 0; i < n; ++ i) if (!Bit(a[i], b)) t.pb(a[i]);
        for (int i = 0; i < n; ++ i) if (Bit(a[i], b)) t.pb(a[i]);
        swap(t, a); int i = 0, j = 0, k = 0; ll cur = 0;
        for (int X = n - 1; X >= 0; -- X){
            int x = a[X];
            while (i < n && (x & mx) + (a[i] & mx) < Mask(b)) ++ i;
            while (j < n && (x & mx) + (a[j] & mx) < Mask(b + 1)) ++ j;
            while (k < n && (x & mx) + (a[k] & mx) < Mask(b) + Mask(b + 1)) ++ k;
            cur += (j - i + n - k); int sum = (x & mx) << 1;
            cur += ((Mask(b) <= sum && sum < Mask(b + 1)) || (sum >= Mask(b + 1) + Mask(b)));
        }
        cur >>= 1ll; cur &= 1ll;
        ans ^= (cur << b);
    }
    cout << ans;
}

int main(){
    if (fopen("pqh.inp", "r")){
        freopen("pqh.inp", "r", stdin);
        freopen("pqh.out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int t = 1; // cin >> t;
    while (t --) solve();
    return 0;
}

Compilation message

xorsum.cpp:19:11: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   19 | void maxl(auto &a, auto b) {a = max(a, b);}
      |           ^~~~
xorsum.cpp:19:20: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   19 | void maxl(auto &a, auto b) {a = max(a, b);}
      |                    ^~~~
xorsum.cpp:20:11: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   20 | void minl(auto &a, auto b) {a = min(a, b);}
      |           ^~~~
xorsum.cpp:20:20: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   20 | void minl(auto &a, auto b) {a = min(a, b);}
      |                    ^~~~
xorsum.cpp: In function 'int main()':
xorsum.cpp:51:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |         freopen("pqh.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
xorsum.cpp:52:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |         freopen("pqh.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 348 KB Output is correct
2 Correct 3 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 305 ms 16944 KB Output is correct
2 Correct 287 ms 16128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 305 ms 16944 KB Output is correct
2 Correct 287 ms 16128 KB Output is correct
3 Correct 413 ms 19084 KB Output is correct
4 Correct 406 ms 18576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 348 KB Output is correct
2 Correct 3 ms 348 KB Output is correct
3 Correct 70 ms 2628 KB Output is correct
4 Correct 67 ms 2616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 348 KB Output is correct
2 Correct 3 ms 348 KB Output is correct
3 Correct 305 ms 16944 KB Output is correct
4 Correct 287 ms 16128 KB Output is correct
5 Correct 413 ms 19084 KB Output is correct
6 Correct 406 ms 18576 KB Output is correct
7 Correct 70 ms 2628 KB Output is correct
8 Correct 67 ms 2616 KB Output is correct
9 Correct 609 ms 21732 KB Output is correct
10 Correct 636 ms 21736 KB Output is correct
11 Correct 624 ms 21740 KB Output is correct