Submission #468239

#TimeUsernameProblemLanguageResultExecution timeMemory
468239Killer2501XOR Sum (info1cup17_xorsum)C++14
100 / 100
748 ms41060 KiB
#include <bits/stdc++.h> #define ll int #define pb push_back #define task "tests" #define pll pair<ll, ll> #define pi pair<ll, pll> #define fi first #define se second using namespace std; const ll mod = 1e15+7; const ll N = 1e6+5; const int base = 313; ll n, m, t, k, T, ans, tong, c[N], a[N], b[N], h[N], dp[N], cnt, top[N], nchain[N], chain, par[N]; vector<pll> adj[N]; ll pw(ll k, ll n) { ll total = 1; for(; n; n >>= 1) { if(n & 1)total = total * k % mod; k = k * k % mod; } return total; } bool check(int j) { int l = 0, r = 0; if(j) { b[0] = b[1] = 0; for(int i = 0; i < n; i ++) { k = (a[i] >> (j-1)) & 1; ++b[k]; } b[1] += b[0]; for(int i = n-1; i >= 0; i --) { k = (a[i] >> (j-1)) & 1; c[--b[k]] = a[i]; } for(int i = 0; i < n; i ++)a[i] = c[i]; } int p = n-1; for(int i = 0; i < n; i ++)l += ((a[i] >> j) & 1); bool ok = 0; for(int i = 0; i < n; i ++) { while(p >= i && (a[i] & ((1<<j)-1)) + (a[p] & ((1<<j)-1)) >= (1<<j)) { r += ((a[p] >> j) & 1); l -= ((a[p] >> j) & 1); --p; } if((a[i] >> j) & 1) { if((r+p-i+1-l)&1)ok = !ok; } else { if((l+n-1-p-r)&1)ok = !ok; } l -= ((a[i] >> j) & 1); if(p < i) { ++p; r -= ((a[p] >> j) & 1); l += ((a[p] >> j) & 1); } } return ok; } void sol() { cin >> n; for(int i = 0; i < n; i ++)cin >> a[i]; for(int i = 0; i < 30; i ++)if(check(i))ans += (1<<i); cout << ans; } int main() { if(fopen(task".in", "r")) { freopen(task".in", "r", stdin); freopen(task".out", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int ntest = 1; //cin >> ntest; while(ntest -- > 0) sol(); } /* 5 1 0 1 2 0 2 3 1 3 5 2 4 6 1 1 4 3 */

Compilation message (stderr)

xorsum.cpp:11:20: warning: overflow in conversion from 'double' to 'int' changes value from '1.000000000000007e+15' to '2147483647' [-Woverflow]
   11 | const ll mod = 1e15+7;
      |                ~~~~^~
xorsum.cpp: In function 'int main()':
xorsum.cpp:86:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   86 |        freopen(task".in", "r", stdin);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
xorsum.cpp:87:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   87 |        freopen(task".out", "w", stdout);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...