# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
468402 | 2021-08-28T02:56:31 Z | cpp219 | XOR Sum (info1cup17_xorsum) | C++14 | 1600 ms | 25068 KB |
#include <bits/stdc++.h> #define ll int #define ld long double #define fs first #define sc second #define debug(y) cout<<y,exit(0) using namespace std; typedef pair<ll,ll> LL; const ll N = 1e6 + 9; const ll Log2 = 23; const ll inf = 1e9 + 7; vector<ll> g[2]; ll n,a[N],pos[N],val[N],ans,b[N]; ll Getval(ll x,ll i){ return (((1 << i + 1) - 1) & x); } bool chk(ll x,ll i){ return (x >> i) & 1; } void updateArr(){ for (ll i = 1;i <= n;i++) b[pos[i]] = a[i]; for (ll i = 1;i <= n;i++) a[i] = b[i]; } int main(){ ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0); #define task "test" if (fopen(task".INP","r")){ freopen(task".INP","r",stdin); freopen(task".out","w",stdout); } cin>>n; for (ll i = 1;i <= n;i++) cin>>a[i]; for (ll bit = 0;bit < 30;bit++){ g[0].clear(); g[1].clear(); for (ll i = 1;i <= n;i++) g[chk(a[i],bit)].push_back(i); ll now = 1; for (auto i : g[0]) pos[i] = now++; for (auto i : g[1]) pos[i] = now++; updateArr(); for (ll i = 1;i <= n;i++) val[i] = Getval(a[i],bit); ll tmp = 0; for (ll i = 1;i <= n;i++){ ll st = lower_bound(val + i,val + n + 1,(1 << bit) - val[i]) - val; ll en = upper_bound(val + i,val + n + 1,(1 << bit + 1) - 1 - val[i]) - val - 1; tmp += en - st + 1; st = lower_bound(val + i,val + n + 1,(1 << bit) + (1 << bit + 1) - val[i]) - val; en = upper_bound(val + i,val + n + 1,(1 << bit + 2) - 2 - val[i]) - val - 1; tmp += en - st + 1; //debug(tmp); //cout<<tmp<<"\n"; } tmp %= 2; //debug(tmp); ans += tmp*(1 << bit); } cout<<ans; } /* stuff you should look for * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * WRITE STUFF DOWN * DON'T GET STUCK ON ONE APPROACH */
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 460 KB | Output is correct |
2 | Correct | 13 ms | 460 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1684 ms | 25068 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1684 ms | 25068 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 460 KB | Output is correct |
2 | Correct | 13 ms | 460 KB | Output is correct |
3 | Incorrect | 386 ms | 2964 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 460 KB | Output is correct |
2 | Correct | 13 ms | 460 KB | Output is correct |
3 | Execution timed out | 1684 ms | 25068 KB | Time limit exceeded |
4 | Halted | 0 ms | 0 KB | - |