#pragma GCC optimize("O3,unroll-loops")
#include<bits/stdc++.h>
using namespace std;
//#define int long long
int n;
int v[1000001];
int pre[1000001];
int newv[1000001];
bool bl[1000001];
unordered_map<int,int> fr;
int mxm=0;
void precalc(int bit)
{
if(n>100000)
for(int i=0;i<=1000000;i++)
bl[i]=0;
mxm=0;
fr.clear();
for(int i=0;i<n;i++)
{
///calc v[i]
if(((1<<bit)&(newv[i]))!=0)
pre[i] = ((pre[i]) | (1<<bit));
v[i] = pre[i];
mxm=max(mxm, v[i]);
if(((1<<bit)&(v[i]+v[i]))!=0)
fr[v[i]]++;
if(n>100000)
{
bl[v[i]] = !bl[v[i]];
}
}
if(n<=100000)
sort(v,v+n);
else
{
for(int i=1;i<=1000000;i++)
{
if(bl[i-1])
bl[i]=!bl[i];
}
}
}
int qry(int x)///returneaza cate numere <= x apar in sirul modificat
{
if(x<0)
return 0;
if(n<=100000)
{
int st,dr,mij;
if(v[0]>x)
return 0;
st=0;
dr=n-1;
while(st<=dr)
{
mij=(st+dr)/2;
if(v[mij]<=x && (mij==n-1 || v[mij+1]>x))
return mij+1;
else if(v[mij]<=x)
st=mij+1;
else
dr=mij-1;
}
return st+1;
}
if(bl[x])
return 1;
return 0;
}
signed main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n;
for(int i=0;i<n;i++)
{
cin>>v[i];
newv[i] = v[i];
pre[i]=0;
}
int rez=0;
for(int bit=0;bit<=28;bit++)
{
precalc(bit);
int cntb=0;
int cnt2=0;
for(int i=0;i<n;i++)
{
int st1,dr1,st2,dr2;
st1 = max((int)0, (1<<bit) - v[i]);
dr1 = (1<<(bit+1)) - v[i] - 1;
dr1 = min(dr1,v[i]-1);
if(st1<=dr1)
cntb += 2 + qry(dr1) - qry(st1-1);
cntb%=2;
st2 = (1<<bit) + (1<<(bit+1)) - v[i];
dr2 = (1<<(bit+1))-1;
dr2 = min(dr2, v[i]-1);
if(st2<=dr2)
cntb += 2 + qry(dr2) - qry(st2-1);
cntb%=2;
if(((1<<bit)&(v[i]+v[i]))!=0)
{
cnt2 += fr[v[i]] - 1;
cnt2 %= 4;
cntb++;
cntb%=2;
}
}
cnt2/=2;
cntb+=cnt2;
cntb=cntb%2;
if(cntb==1)
rez += (1<<bit);
}
cout<<rez;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
468 KB |
Output is correct |
2 |
Correct |
14 ms |
480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
611 ms |
13148 KB |
Output is correct |
2 |
Correct |
562 ms |
12228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
611 ms |
13148 KB |
Output is correct |
2 |
Correct |
562 ms |
12228 KB |
Output is correct |
3 |
Correct |
1254 ms |
23960 KB |
Output is correct |
4 |
Correct |
1171 ms |
23272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
468 KB |
Output is correct |
2 |
Correct |
14 ms |
480 KB |
Output is correct |
3 |
Correct |
398 ms |
3788 KB |
Output is correct |
4 |
Correct |
395 ms |
3752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
468 KB |
Output is correct |
2 |
Correct |
14 ms |
480 KB |
Output is correct |
3 |
Correct |
611 ms |
13148 KB |
Output is correct |
4 |
Correct |
562 ms |
12228 KB |
Output is correct |
5 |
Correct |
1254 ms |
23960 KB |
Output is correct |
6 |
Correct |
1171 ms |
23272 KB |
Output is correct |
7 |
Correct |
398 ms |
3788 KB |
Output is correct |
8 |
Correct |
395 ms |
3752 KB |
Output is correct |
9 |
Runtime error |
1474 ms |
73660 KB |
Execution killed with signal 11 |
10 |
Halted |
0 ms |
0 KB |
- |