Submission #1139152

#TimeUsernameProblemLanguageResultExecution timeMemory
1139152KasymKXOR Sum (info1cup17_xorsum)C++20
100 / 100
593 ms8240 KiB
#include "bits/stdc++.h" using namespace std; #define ff first #define ss second #define all(v) v.begin(), v.end() #define ll long long #define pb push_back #define pii pair<int, int> #define pli pair<ll, int> #define pll pair<ll, ll> #define tr(i, c) for(auto i = c.begin(); i != c.end(); ++i) #define wr puts("----------------") template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;} template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;} const int N = 1e6+5; int v[N], A[N]; int main(){ int n, answer=0; scanf("%d", &n); for(int i = 1; i <= n; ++i) scanf("%d", v+i); for(int j = 0; j <= 30; ++j){ int sm=0, op=0, ad=0; if(j){ for(int i = 1; i <= n; ++i) if(!(v[i]>>(j-1)&1)) A[++op]=v[i]; } if(j){ for(int i = 1; i <= n; ++i) if(v[i]>>(j-1)&1) A[++op]=v[i]; } if(j){ for(int i = 1; i <= n; ++i) v[i]=A[i], A[i]=v[i]%(1<<j); } for(int i = 1; i <= n; ++i) sm+=(!(v[i]>>j&1)); int id1=1, id2=n; while(id1<=n){ while(A[id1]+A[id2]>=(1<<j)) id2--; ad+=(n-id2), id1++; } for(int i = 1; i <= n; ++i) ad+=(A[i]>=((1<<j)>>1)); int f=ad/2+sm*(n-sm); if(f&1) answer+=(1<<j); } printf("%d\n", answer); return 0; }

Compilation message (stderr)

xorsum.cpp: In function 'int main()':
xorsum.cpp:20:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
xorsum.cpp:22:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |                 scanf("%d", v+i);
      |                 ~~~~~^~~~~~~~~~~
#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...