Submission #362358

# Submission time Handle Problem Language Result Execution time Memory
362358 2021-02-02T18:49:58 Z lukameladze XOR Sum (info1cup17_xorsum) C++14
0 / 100
983 ms 131072 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[N*10];
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];
     }
     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;
          for (int j=1; j<=n; j++) {
               b[j]+=a[j]&pw[i];
               c1[j]=b[j];
               mx=max(mx,c1[j]);
          }
          for (int j=1; j<=n; j++) {
          	cnt[c1[j]]++;
		}
		for (int j=0; j<=mx; j++) {
			if (j>0)
			cnt[j]+=cnt[j-1];
		}
		for (int j=1; j<=n; j++) {
			c[cnt[c1[j]]]=c1[j];
			cnt[c1[j]]--;
		}
		for (int j=0; j<=mx; j++) {
			cnt[j]=0;
		}
          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);
     }
     
     cout<<answ<<endl;
}

Compilation message

xorsum.cpp: In function 'int main()':
xorsum.cpp:14:16: warning: iteration 34 invokes undefined behavior [-Waggressive-loop-optimizations]
   14 |           pw[i]=pw[i-1]*2;
      |           ~~~~~^~~~~~~~~~
xorsum.cpp:13:20: note: within this loop
   13 |      for (int i=1;i<=35; i++) {
      |                   ~^~~~
# Verdict Execution time Memory Grader output
1 Runtime error 202 ms 131072 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 983 ms 47468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 983 ms 47468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 202 ms 131072 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 202 ms 131072 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -