Submission #1149484

#TimeUsernameProblemLanguageResultExecution timeMemory
1149484KluydQXOR Sum (info1cup17_xorsum)C++20
100 / 100
709 ms21916 KiB
#include <bits/stdc++.h> #define respagold ios_base::sync_with_stdio(0), cin.tie(0); #define ll long long #define int2 __int128_t #define FOR( i, x, n, d ) for( int i = x; i <= n; i += d ) #define FORR( i, x, n, d ) for( int i = x; i >= n; i -= d ) #define F first #define S second #define all(x) x.begin(), x.end() #define sz(x) (int)(x.size()) #define pb push_back #define ins insert #define lb lower_bound #define ub upper_bound #define pii pair <int, int> #define mkp make_pair using namespace std; const int N = 1e6 + 123; const int inf = 2e9; const int MOD = 1e9 + 7; const int MOD1 = 998244353; const int P = 6547; int a[N], b[N], c[N], n, m, x, y, z, w; mt19937 rng( chrono::steady_clock::now().time_since_epoch().count()); int rand( int l, int r ) { uniform_int_distribution <int> uid( l, r ); return uid( rng ); } vector <int> v, v1, v0; bool cmp( int i1, int i2 ) { return a[i1] < a[i2]; } void solve() { cin >> n; FOR( i, 1, n, 1 ) cin >> b[i]; FOR( k, 0, 30, 1 ) { FOR( i, 1, n, 1 ) a[i] = b[i] & ( (1 << k + 1) - 1 ); if( k == 0 ) { FOR( i, 1, n, 1 ) v.pb(i); sort( all( v ), cmp ); } else { v1.clear(), v0.clear(); for( auto i : v ) { if( (a[i] >> k) & 1 ) v1.pb(i); else v0.pb(i); } v.clear(); for( auto i : v0 ) v.pb(i); for( auto i : v1 ) v.pb(i); } w = 0; FOR( i, 1, n, 1 ) a[i] = b[v[i - 1]] & ( (1 << k + 1) - 1 ); int u1 = n, u2 = n, u3 = n; ll ans = 0; FOR( i, 1, n, 1 ) { while( a[u1] + a[i] >= (1 << k) && u1 > 0 ) u1 --; while( a[u2] + a[i] >= (1 << (k + 1)) && u2 > 0 ) u2 --; while( a[u3] + a[i] >= (1 << (k + 1)) + (1 << k) && u3 > 0 ) u3 --; ans += u2 - u1; ans += n - u3; } FOR( i, 1, n, 1 ) if( (1 << k) & (a[i] * 2) ) ans ++; ans /= 2; if( ans % 2 ) x += ( 1 << k ); } cout << x; } signed main() { // freopen("connect.in", "r", stdin); // freopen("connect.out", "w", stdout); respagold int test = 1; if( !test ) cin >> test; while( test -- ) { solve(); } } // solved by KluydQ
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...