이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
int pos[mxn];
vector<int> v[2];
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;
v[0].clear();v[1].clear();
for(int i = 1;i<=n;i++){
if(arr[pos[i]]&(1<<bit))v[1].push_back(pos[i]);
else v[0].push_back(pos[i]);
}
int pt = 0;
for(auto &i:v[0]){
brr[++pt] = arr[i]&((1ll<<(bit+1))-1);
pos[pt] = i;
}
for(auto &i:v[1]){
brr[++pt] = arr[i]&((1ll<<(bit+1))-1);
pos[pt] = i;
}
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 = 1;i<=n;i++)pos[i] = 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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |