Submission #900541

# Submission time Handle Problem Language Result Execution time Memory
900541 2024-01-08T13:15:38 Z pcc XOR Sum (info1cup17_xorsum) C++17
56 / 100
1600 ms 18772 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>


const int H = 30;
const int mxn = 1e6+10;
int arr[mxn],brr[mxn];
int ans;
int cnt[mxn];
int n;
int sum;

inline void add(int p){
	sum += cnt[p];
	return;
}
inline void del(int p){
	sum -= cnt[p];
	return;
}

inline int calc(int bit){
	int h = 1<<(bit+1);
	h--;
	memset(cnt,0,sizeof(cnt));
	sum = 0;
	for(int i = 1;i<=n;i++){
		brr[i] = arr[i];
		brr[i] &= h;
	}
	sort(brr+1,brr+n+1);
	int re = 0;
	int pl = 0,pr = 0;
	//cout<<bit<<":";for(int i = 1;i<=n;i++)cout<<brr[i]<<' ';cout<<endl;
	for(int i = n;i>=1;i--){
		cnt[i]++;
		if(pl<=i&&pr>i)sum++;
		int lp = (1<<bit)-brr[i],rp = (1ll<<(bit+1))-brr[i];
		while(pr<=n&&brr[pr]<rp)add(pr++);
		while(pl<=n&&brr[pl]<lp)del(pl++);
		//cout<<i<<','<<pl<<','<<pr<<','<<sum<<endl;
		re += sum;
	}

	memset(cnt,0,sizeof(cnt));
	sum = 0;
	pl = pr = 0;
	for(int i = n;i>=1;i--){
		cnt[i]++;
		if(pl<=i&&pr>i)sum++;
		ll lp = (1ll<<bit)*3-brr[i],rp = (1ll<<(bit+2))-brr[i];
		while(pr<=n&&brr[pr]<rp)add(pr++);
		while(pl<=n&&brr[pl]<lp)del(pl++);
		re += sum;
	}

	return re&1;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i = 1;i<=n;i++)cin>>arr[i];
	for(int i =0;i<=H;i++)ans ^= calc(i)<<i;
	//for(int i = 0;i<=H;i++)cout<<i<<":"<<calc(i)<<endl;
	cout<<ans<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 12 ms 6744 KB Output is correct
2 Correct 12 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1578 ms 12176 KB Output is correct
2 Correct 1433 ms 16220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1578 ms 12176 KB Output is correct
2 Correct 1433 ms 16220 KB Output is correct
3 Execution timed out 1628 ms 18772 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 6744 KB Output is correct
2 Correct 12 ms 6748 KB Output is correct
3 Correct 205 ms 9760 KB Output is correct
4 Correct 203 ms 9564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 6744 KB Output is correct
2 Correct 12 ms 6748 KB Output is correct
3 Correct 1578 ms 12176 KB Output is correct
4 Correct 1433 ms 16220 KB Output is correct
5 Execution timed out 1628 ms 18772 KB Time limit exceeded
6 Halted 0 ms 0 KB -