Submission #362461

# Submission time Handle Problem Language Result Execution time Memory
362461 2021-02-03T10:14:53 Z lukameladze XOR Sum (info1cup17_xorsum) C++14
100 / 100
1161 ms 48876 KB
# include <bits/stdc++.h>
using namespace std;
const int N=1e6+5;
long long le[N],ri[N],mid,lee,rii;
long long a[N],b[N],c[N],mp[35],ans,n,answ,idx,idx1,pw[35],bb,mx,c1[N],cnt[10],mx1;
int main() {
     std::ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
     cin>>n;
     for (int i=1; i<=n; i++) {
          cin>>a[i];
          mx1=max(mx1,a[i]);
     }
     pw[0]=1;
     for (int i=1;i<=35; i++) {
          pw[i]=pw[i-1]*2;
     }
     for (int i=0; i<=30; i++) {
     	mx=0;
     	cnt[1]=cnt[0]=0;
          for (int j=1; j<=n; j++) {
               b[j]+=a[j]&pw[i];
               if (a[j]&pw[i]) cnt[1]++;
               else cnt[0]++;
          }
          cnt[1]+=cnt[0];
          for (int j=n; j>=1; j--) {
               if(a[j]&pw[i])
               c[cnt[1]]=a[j], cnt[1]--;
               else c[cnt[0]]=a[j], cnt[0]--;
          }
          for (int j=1; j<=n; j++) {
          a[j]=c[j];
          c[j]&=(pw[i+1]-1);//, cout<<c[j]<<" ";
          }
          //cout<<endl;
          idx=n;
          for (int j=1; j<=n; j++) {
               idx=max(idx,j+1LL);
               bb=0;
               while (c[j]+c[idx]>=pw[i] && idx>j) {
                    idx--;         
				bb=1;           
               }
               if (bb==1)
               idx++;
               if (c[j]+c[idx]<pw[i] || idx>n) le[j]=-1;
               else le[j]=idx;
          }
          idx=n;
          for (int j=1; j<=n; j++) {
               idx=max(idx,j+1LL);
               while (c[j]+c[idx]>=pw[i+1] && idx>j+1) {
                    idx--;
               }
               if (c[j]+c[idx]>=pw[i+1] || idx>n) ri[j]=-1;
               else
               ri[j]=idx;
          }
          for (int j=1; j<=n; j++) {
               if (le[j]!=-1 && ri[j]!=-1)
               mp[i]+=ri[j]-le[j]+1;
          }
          idx=n;
          for (int j=1; j<=n; j++) {
               idx=max(idx,j+1LL);
               bb=0;
               while (c[j]+c[idx]>=pw[i+1]+pw[i] && idx>j) {
               	bb=1;
                    idx--;                    
               }
               if (bb==1)
               idx++;
               if (c[j]+c[idx]<pw[i+1]+pw[i] || idx>n) le[j]=-1;
               else le[j]=idx;
          }
          idx=n;
          for (int j=1; j<=n; j++) {
               idx=max(idx,j+1LL);
               while (c[j]+c[idx]>=pw[i+2] && idx>j+1) {
                    idx--;
               }
               if (c[j]+c[idx]>=pw[i+2] || idx>n) ri[j]=-1;
               else
               ri[j]=idx;
          }
          for (int j=1; j<=n; j++) {           
		    if (le[j]!=-1 && ri[j]!=-1)
               mp[i]+=ri[j]-le[j]+1;
          }
     }
     for (int i=0; i<=30; i++) {
          if (mp[i]%2) answ+=(1LL<<i);
     }
   for (int i=1; i<=n; i++)
     answ^=(2*a[i]);
     cout<<answ<<endl;
}

Compilation message

xorsum.cpp: In function 'int main()':
xorsum.cpp:94:4: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   94 |    for (int i=1; i<=n; i++)
      |    ^~~
xorsum.cpp:96:6: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   96 |      cout<<answ<<endl;
      |      ^~~~
xorsum.cpp:15:16: warning: iteration 34 invokes undefined behavior [-Waggressive-loop-optimizations]
   15 |           pw[i]=pw[i-1]*2;
      |           ~~~~~^~~~~~~~~~
xorsum.cpp:14:20: note: within this loop
   14 |      for (int i=1;i<=35; i++) {
      |                   ~^~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 620 KB Output is correct
2 Correct 5 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 763 ms 44268 KB Output is correct
2 Correct 749 ms 41196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 763 ms 44268 KB Output is correct
2 Correct 749 ms 41196 KB Output is correct
3 Correct 945 ms 46268 KB Output is correct
4 Correct 909 ms 44636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 620 KB Output is correct
2 Correct 5 ms 620 KB Output is correct
3 Correct 118 ms 5228 KB Output is correct
4 Correct 119 ms 5228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 620 KB Output is correct
2 Correct 5 ms 620 KB Output is correct
3 Correct 763 ms 44268 KB Output is correct
4 Correct 749 ms 41196 KB Output is correct
5 Correct 945 ms 46268 KB Output is correct
6 Correct 909 ms 44636 KB Output is correct
7 Correct 118 ms 5228 KB Output is correct
8 Correct 119 ms 5228 KB Output is correct
9 Correct 1132 ms 48868 KB Output is correct
10 Correct 1113 ms 48876 KB Output is correct
11 Correct 1161 ms 48832 KB Output is correct