Submission #97866

#TimeUsernameProblemLanguageResultExecution timeMemory
97866mohammedehab2002XOR Sum (info1cup17_xorsum)C++11
100 / 100
1018 ms21768 KiB
#include <iostream> #include <algorithm> #include <vector> using namespace std; vector<int> v; int f(unsigned int x) { int r=v.size(),ans=0; for (int l=0;l<v.size();l++) { r=max(r,l); while (r>l && v[l]+v[r-1]>=x) r--; ans^=(r-l)%2; } return ans; } int main() { int n,ans=0; scanf("%d",&n); for (int i=0;i<n;i++) { int a; scanf("%d",&a); v.push_back(a); } sort(v.begin(),v.end()); for (unsigned int i=(1<<29);i;i/=2) { vector<int> v1,v2; for (int j:v) { if (j<2*i) v1.push_back(j); else v2.push_back(j-2*i); } v.clear(); merge(v1.begin(),v1.end(),v2.begin(),v2.end(),back_inserter(v)); int cnt=(f(4*i)^f(3*i)^f(2*i)^f(i)); ans+=i*cnt; } printf("%d",ans); }

Compilation message (stderr)

xorsum.cpp: In function 'int f(unsigned int)':
xorsum.cpp:9:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int l=0;l<v.size();l++)
               ~^~~~~~~~~
xorsum.cpp:12:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while (r>l && v[l]+v[r-1]>=x)
xorsum.cpp: In function 'int main()':
xorsum.cpp:34:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if (j<2*i)
        ~^~~~
xorsum.cpp:21:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
xorsum.cpp:25:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&a);
   ~~~~~^~~~~~~~~
#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...