Submission #799607

# Submission time Handle Problem Language Result Execution time Memory
799607 2023-07-31T16:35:00 Z Darren0724 XOR Sum (info1cup17_xorsum) C++17
100 / 100
607 ms 39604 KB
#pragma GCC optimize("Ofast","O3","unroll-loops")
#pragma GCC target("avx2")
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define rz resize
#define pb emplace_back
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define ACorz ios_base::sync_with_stdio(false);cin.tie(0);
//#define endl '\n'
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int INF=1e9,INF2=2e9;
const int mod=1e9+7;
const int mod1=998244353;
const int N=100;
const int K=45000;
const int M=5000;

signed main(){
    ACorz;
    int n;cin>>n;
    vector<int> v(n);
    vector<pair<int,int>> a(n);
    int ans=0;
    for(int i=0;i<n;i++){
        cin>>v[i];
        if(n%2==0){
            ans^=v[i];
        }
        a[i]={v[i]%2,v[i]};
    }
    sort(all(a));
    int p=2;
    for(int i=1;i<=29;i++){
        int cnt=0;
        int t=n-1;
        for(int j=0;j<n;j++){
            while(t>=0&&a[t].first+a[j].first>=p){
                t--;
            }
            cnt+=(n-1-t);
        }
        for(int j=0;j<n;j++){
            if(a[j].first+a[j].first>=p){
                cnt++;
            }
        }
        cnt/=2;
        //cout<<cnt<<endl;
        if(cnt&1){
            ans^=p;
        }
        vector<pair<int,int>> a1,a2;
        for(int j=0;j<n;j++){
            if(a[j].second&p){
                a[j].first+=p;
                a2.push_back(a[j]);
            }
            else{
                a1.push_back(a[j]);
            }
        }
        a.clear();
        for(auto j:a1){
            a.push_back(j);
        }
        for(auto j:a2){
            a.push_back(j);
        }
        p<<=1;
    }
    cout<<ans<<endl;

    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 340 KB Output is correct
2 Correct 3 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 393 ms 29456 KB Output is correct
2 Correct 367 ms 26828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 393 ms 29456 KB Output is correct
2 Correct 367 ms 26828 KB Output is correct
3 Correct 480 ms 29404 KB Output is correct
4 Correct 457 ms 33916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 340 KB Output is correct
2 Correct 3 ms 340 KB Output is correct
3 Correct 63 ms 3324 KB Output is correct
4 Correct 63 ms 3268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 340 KB Output is correct
2 Correct 3 ms 340 KB Output is correct
3 Correct 393 ms 29456 KB Output is correct
4 Correct 367 ms 26828 KB Output is correct
5 Correct 480 ms 29404 KB Output is correct
6 Correct 457 ms 33916 KB Output is correct
7 Correct 63 ms 3324 KB Output is correct
8 Correct 63 ms 3268 KB Output is correct
9 Correct 607 ms 39396 KB Output is correct
10 Correct 604 ms 39604 KB Output is correct
11 Correct 595 ms 39424 KB Output is correct