Submission #362364

# Submission time Handle Problem Language Result Execution time Memory
362364 2021-02-02T19:14:25 Z keta_tsimakuridze XOR Sum (info1cup17_xorsum) C++14
45 / 100
1600 ms 48596 KB
#include<bits/stdc++.h>
#define int long long
#define f first
#define s second
using namespace std;
const int N=1e6+5;
int a[N],ind[N],s[N],n,cnt,c[2],ans,cur;
vector< pair< pair<int,int >,int >  > v;
void Sort(){
	vector< pair< pair<int,int >,int >  > C[N];
	for(int k=1;k<=n;k++){
		C[k].clear();
	}
	for(int i=0;i<v.size();i++){
		C[v[i].f.s].push_back(v[i]);
	}
	
	v.clear();
	
	for(int k=1;k<=n;k++){
		for(int i=0;i<C[k].size();i++)
		v.push_back(C[k][i]);
	}
	for(int k=1;k<=n;k++){
		C[k].clear();
	}
	for(int i=0;i<v.size();i++){
		C[v[i].f.f].push_back(v[i]);
	}
	
	v.clear();
	
	for(int k=1;k<=n;k++){
		for(int i=0;i<C[k].size();i++)
		v.push_back(C[k][i]);
	}
	
}
main(){
	cin>>n;
	for(int k=1;k<=n;k++){
		cin>>a[k];
		cnt+=c[(a[k]&1)^1];
		c[a[k]&1]++;
		if(a[k]&1) ind[k]=2;
		else ind[k]=1;
		s[k]=a[k]&1;
	}
	if(cnt%2) ans=1;
 
	for(int i=1;i<=30;i++){
		v.clear();
		for(int k=1;k<=n;k++){
			if((1<<i)&a[k]) v.push_back({{2,ind[k]},k});
			else v.push_back({{1,ind[k]},k});
			s[k]+=(1<<i)&a[k];
		}//Sort();
 sort(v.begin(),v.end());
		// 
		cur=0;
		for(int k=0;k<v.size();k++){
			if(!k || v[k].f.f != v[k-1].f.f || v[k].f.s!=v[k-1 ].f.s) cur++;
			ind[v[k].s]=cur; 
		//	cout<<v[k].s<<" ";
		}
		v.push_back({{0,0},0});
		for(int k=v.size()-1;k>=1;k--){
		           swap(v[k],v[k-1]);
		}
	           //	cout<<endl;
		cnt=0;
		// 2^i  <= sum  <= 2^(i+1)  ||    2^(i+1) + 2^i  <= sum <= 2^(i+2)-2 
		int l=n,r=n,l1=n,r1=n;
		for(int k=1;k<=n;k++){
		         while(r && s[v[r].s] + s[v[k].s] >= (1ll<<(i+1)) ) r--;
		         while(l && s[v[l].s] + s[v[k].s] >= (1ll<<i) ) l--;
		         //l +1 r 
		     //    cout << l<<"_"<<r<<endl;
		         cnt += r-l;
		         while( l1&&s[v[l1].s] + s[v[k].s] >=((1ll<<(i+1))+(1ll<<i)) ) l1--;
		         cnt+=n-l1;
		}
		
		int c1=0;
		for(int k=1;k<=n;k++){
		           if((2*a[k])&(1ll<<i)) c1++;
		}
	//	cout<<c1<<endl;
		if((c1+ (cnt-c1)/2)%2==1) ans+=1ll<<i;
		
	}
	cout<<ans;
}

Compilation message

xorsum.cpp: In function 'void Sort()':
xorsum.cpp:14:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<std::pair<long long int, long long int>, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |  for(int i=0;i<v.size();i++){
      |              ~^~~~~~~~~
xorsum.cpp:21:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<std::pair<long long int, long long int>, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |   for(int i=0;i<C[k].size();i++)
      |               ~^~~~~~~~~~~~
xorsum.cpp:27:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<std::pair<long long int, long long int>, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |  for(int i=0;i<v.size();i++){
      |              ~^~~~~~~~~
xorsum.cpp:34:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<std::pair<long long int, long long int>, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |   for(int i=0;i<C[k].size();i++)
      |               ~^~~~~~~~~~~~
xorsum.cpp: At global scope:
xorsum.cpp:39:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   39 | main(){
      |      ^
xorsum.cpp: In function 'int main()':
xorsum.cpp:61:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<std::pair<long long int, long long int>, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |   for(int k=0;k<v.size();k++){
      |               ~^~~~~~~~~
xorsum.cpp:73:20: warning: unused variable 'r1' [-Wunused-variable]
   73 |   int l=n,r=n,l1=n,r1=n;
      |                    ^~
# Verdict Execution time Memory Grader output
1 Correct 18 ms 620 KB Output is correct
2 Correct 18 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1678 ms 48596 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1678 ms 48596 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 18 ms 620 KB Output is correct
2 Correct 18 ms 620 KB Output is correct
3 Correct 550 ms 5856 KB Output is correct
4 Correct 539 ms 5856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 620 KB Output is correct
2 Correct 18 ms 620 KB Output is correct
3 Execution timed out 1678 ms 48596 KB Time limit exceeded
4 Halted 0 ms 0 KB -