#include "bits/stdc++.h"
using namespace std;
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
using ll = long long;
using ld = long double;
#define pb push_back
#define ff first
#define ss second
#define sz(x) (ll)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
void freopen(string s) { freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); }
void IOIGold2024_In_Shaa_Allah() { ios_base::sync_with_stdio(false); cin.tie(NULL); }
ll binmul(ll a, ll b, ll c) { ll res = 0; while(b) { if(b&1) (res += a) %= c; (a += a) %= c; b >>= 1; } return res; }
ll binpow(ll a, ll b, ll c) { ll res = 1; while(b) { if(b&1) (res *= a) %= c; (a *= a) %= c; b >>= 1; } return res; }
template<typename T> T gcd(T a, T b) { if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b) { return a/gcd(a, b)*b; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ld rnd() { return rng()%INT_MAX*1.0/INT_MAX; }
const ll inf = 1e18+7, MX = LLONG_MAX, MN = LLONG_MIN;
const ll mod = 1e9+7, N = 1e6+5;
ll a[N];
void kigash() {
ll n;
cin>>n;
vector<pair<ll, ll>> c0, c1;
for(ll i=1; i<=n; i++) {
cin>>a[i];
if(a[i]&1) c1.pb({0, i});
else c0.pb({0, i});
}
ll ans = 0;
for(ll k=0; k<30; k++) {
// cout<<k<<":\nc0:\n";
// for(auto [x, id]: c0) cout<<x<<" "<<id<<"\n";
// cout<<"c1:\n";
// for(auto [x, id]: c1) cout<<x<<" "<<id<<"\n";
ll j = 0, val = (1ll<<k), cnt = 0;
for(ll i=sz(c0)-1; i>=0; i--) {
ll x = c0[i].ff, id = c0[i].ss;
while(j<sz(c0) && c0[j].ff+x<val) j++;
if(j>i) break;
cnt += sz(c0)-j-(sz(c0)-i-1);
}
j = 0;
for(ll i=sz(c1)-1; i>=0; i--) {
ll x = c1[i].ff, id = c1[i].ss;
while(j<sz(c1) && c1[j].ff+x<val) j++;
if(j>i) break;
cnt += sz(c1)-j-(sz(c1)-i-1);
}
// cnt /= 2;
// cout<<cnt<<" ";
j = sz(c1)-1;
for(ll i=0; i<sz(c0); i++) {
ll x = c0[i].ff, id = c0[i].ss;
while(j>-1 && c1[j].ff+x>=val) j--;
cnt += j+1;
}
// cout<<cnt<<"\n\n";
if(cnt&1) ans += val;
vector<pair<ll, ll>> C0, C1;
for(ll i=0; i<sz(c0); i++) {
ll x = c0[i].ff, id = c0[i].ss;
if(a[id]&(val*2)) C1.pb({x, id});
else C0.pb({x, id});
}
for(ll i=0; i<sz(c1); i++) {
ll x = c1[i].ff, id = c1[i].ss;
if(a[id]&(val*2)) C1.pb({x+val, id});
else C0.pb({x+val, id});
}
c0 = C0, c1 = C1;
}
cout<<ans<<"\n";
return;
}
signed main(/*Kigash Amir*/) {
// freopen("");
IOIGold2024_In_Shaa_Allah();
ll tt = 1;
// cin>>tt;
for(ll i=1; i<=tt; i++) {
kigash();
}
}
Compilation message
xorsum.cpp: In function 'void kigash()':
xorsum.cpp:47:30: warning: unused variable 'id' [-Wunused-variable]
47 | ll x = c0[i].ff, id = c0[i].ss;
| ^~
xorsum.cpp:54:30: warning: unused variable 'id' [-Wunused-variable]
54 | ll x = c1[i].ff, id = c1[i].ss;
| ^~
xorsum.cpp:63:30: warning: unused variable 'id' [-Wunused-variable]
63 | ll x = c0[i].ff, id = c0[i].ss;
| ^~
xorsum.cpp: In function 'void freopen(std::string)':
xorsum.cpp:17:33: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
17 | void freopen(string s) { freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
xorsum.cpp:17:73: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
17 | void freopen(string s) { freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
840 KB |
Output is correct |
2 |
Correct |
3 ms |
736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
720 ms |
87368 KB |
Output is correct |
2 |
Correct |
671 ms |
84024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
720 ms |
87368 KB |
Output is correct |
2 |
Correct |
671 ms |
84024 KB |
Output is correct |
3 |
Correct |
875 ms |
90628 KB |
Output is correct |
4 |
Correct |
805 ms |
87564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
840 KB |
Output is correct |
2 |
Correct |
3 ms |
736 KB |
Output is correct |
3 |
Correct |
61 ms |
11332 KB |
Output is correct |
4 |
Correct |
63 ms |
11328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
840 KB |
Output is correct |
2 |
Correct |
3 ms |
736 KB |
Output is correct |
3 |
Correct |
720 ms |
87368 KB |
Output is correct |
4 |
Correct |
671 ms |
84024 KB |
Output is correct |
5 |
Correct |
875 ms |
90628 KB |
Output is correct |
6 |
Correct |
805 ms |
87564 KB |
Output is correct |
7 |
Correct |
61 ms |
11332 KB |
Output is correct |
8 |
Correct |
63 ms |
11328 KB |
Output is correct |
9 |
Correct |
985 ms |
85664 KB |
Output is correct |
10 |
Correct |
1062 ms |
86264 KB |
Output is correct |
11 |
Correct |
934 ms |
87440 KB |
Output is correct |