답안 #362352

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
362352 2021-02-02T18:33:18 Z keta_tsimakuridze XOR Sum (info1cup17_xorsum) C++14
45 / 100
1146 ms 131076 KB
#include<bits/stdc++.h>
#define f first
#define s second
using namespace std;
const int N=1e6+5,mod=1e9+7;
int a[N],ind[N],s[N],n,cnt,c[2],ans,cur,idx[N];
vector< pair< pair<int,int >,int >  > C[N],v;
void Sort(){
	
	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();

		// 
		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] >= (1<<(i+1)) ) r--;
		         while(l && s[v[l].s] + s[v[k].s] >= (1<<i) ) l--;
		         //l +1 r 
		     //    cout << l<<"_"<<r<<endl;
		         cnt += r-l;
		         while( l1&&s[v[l1].s] + s[v[k].s] >=((1<<(i+1))+(1<<i)) ) l1--;
		         cnt+=n-l1;
		}
		
		int c1=0;
		for(int k=1;k<=n;k++){
		           if((2*a[k])&(1<<i)) c1++;
		}
	//	cout<<c1<<endl;
		if((c1+ (cnt-c1)/2)%2==1) ans+=1<<i;
		
	}
	cout<<ans;
}

Compilation message

xorsum.cpp: In function 'void Sort()':
xorsum.cpp:13:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |  for(int i=0;i<v.size();i++){
      |              ~^~~~~~~~~
xorsum.cpp:20:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |   for(int i=0;i<C[k].size();i++)
      |               ~^~~~~~~~~~~~
xorsum.cpp:26:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |  for(int i=0;i<v.size();i++){
      |              ~^~~~~~~~~
xorsum.cpp:33:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |   for(int i=0;i<C[k].size();i++)
      |               ~^~~~~~~~~~~~
xorsum.cpp: At global scope:
xorsum.cpp:38:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   38 | main(){
      |      ^
xorsum.cpp: In function 'int main()':
xorsum.cpp:60:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |   for(int k=0;k<v.size();k++){
      |               ~^~~~~~~~~
xorsum.cpp:72:20: warning: unused variable 'r1' [-Wunused-variable]
   72 |   int l=n,r=n,l1=n,r1=n;
      |                    ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 24428 KB Output is correct
2 Correct 28 ms 24556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1146 ms 131076 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1146 ms 131076 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 24428 KB Output is correct
2 Correct 28 ms 24556 KB Output is correct
3 Correct 387 ms 43744 KB Output is correct
4 Correct 400 ms 43852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 24428 KB Output is correct
2 Correct 28 ms 24556 KB Output is correct
3 Runtime error 1146 ms 131076 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -