Submission #1139716

#TimeUsernameProblemLanguageResultExecution timeMemory
1139716KerimXOR Sum (info1cup17_xorsum)C++20
100 / 100
404 ms19604 KiB
#include "bits/stdc++.h" #define ff first #define ss second #define ll long long using namespace std; const int N = 1e6+5; int a[N]; vector<int> val[2], tmp[2]; ll uly(vector<int> &A, vector<int> &B, int K){ ll cnt = 0; int sz = (int)B.size() - 1; int p = sz; for (auto x: A){ while (p >= 0 and x+B[p]>=K) p -= 1; cnt += sz - p; } return cnt; } ll kici(vector<int> &A, vector<int> &B, int K){ return (ll)A.size()*(ll)B.size() - uly(A, B, K); } int main(){ // freopen("file.in", "r", stdin); int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", a+i); vector<pair<int,int> > tries{{0,0}, {1,1}, {0, 1}}; int ans = 0; for (int k = 0; k < 30; k++){ for (int j = 0; j < 2; j++) tmp[j].clear(), val[j].clear(); for (int i = 0; i < n; i++){ val[a[i]>>k&1].push_back(a[i]%(1<<k)); tmp[a[i]>>k&1].push_back(a[i]); } int p = 0; for (auto y: tmp[0]) a[p++] = y; for (auto y: tmp[1]) a[p++] = y; int K = (1<<k); int n00 = uly(val[0], val[0], K); //p+q>=K int n11 = uly(val[1], val[1], K); //p+q>=K int n01 = kici(val[0], val[1], K); //p+q<K //remove duplicates for (auto A: val[0]) n00 += (A+A >= K); n00 /= 2; //remove duplicates for (auto A: val[1]) n11 += (A+A >= K); n11 /= 2; int cnt = n00 + n11 + n01; if (cnt&1) ans |= (1<<k); } printf("%d\n", ans); }

Compilation message (stderr)

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