Submission #215243

# Submission time Handle Problem Language Result Execution time Memory
215243 2020-03-26T11:12:34 Z wendy_virgo XOR Sum (info1cup17_xorsum) C++14
0 / 100
1600 ms 16108 KB
#include <bits/stdc++.h>

using namespace std;

template<typename TH>
void _dbg(const char* sdbg, TH h)
{
	cerr << sdbg << " = " << h << "\n";
}

template<typename TH, typename... TA>
void _dbg(const char* sdbg, TH h, TA... t)
{
	while (*sdbg != ',') cerr << *sdbg++;
	cerr << " = " << h << ",";
	_dbg(sdbg + 1, t...);
}

#define db(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define chkpt cerr << "--- Checkpoint here ---\n";

const int N=1e6+6;

int n;
int64_t a[N];

void Sub1(){
    int ans=0;
    for(int i=1;i<=n;++i){
        for(int j=i;j<=n;++j){
            ans^=(a[i]+a[j]);
        }
    }
    cout<<ans<<'\n';
}

int Check(int pos){
    int res=0;
    vector<vector<int>> vec(2);
    for(int i=1;i<=n;++i){
        int64_t val=0;
        for(int j=0;j<pos;++j){
            if((a[i]>>j)&1){
                val|=1<<j;
            }
        }
        vec[(a[i]>>pos)&1].push_back(val);
    }
    for(int i=0;i<2;++i){
        sort(begin(vec[i]),end(vec[i]));
    }
    for(int i=0;i<vec[0].size();++i){
        int64_t val=(1<<pos)-vec[0][i];
        int lo=0,hi=i,pos=-1;
        while(lo<=hi){
            int mi=(lo+hi)/2;
            if(vec[0][mi]>=val){
                pos=mi;
                hi=mi-1;
            }
            else{
                lo=mi+1;
            }
        }
        if(~pos){
            res^=((i-pos+1)%2);
        }
    }
    for(int i=0;i<vec[1].size();++i){
        int64_t val=(1<<pos)-vec[1][i];
        int lo=0,hi=i,pos=-1;
        while(lo<=hi){
            int mi=(lo+hi)/2;
            if(vec[1][mi]>=val){
                pos=mi;
                hi=mi-1;
            }
            else{
                lo=mi+1;
            }
        }
        if(~pos){
            res^=((i-pos+1)%2);
        }
    }
    for(int i=0;i<vec[0].size();++i){
        int64_t val=(1<<pos)-vec[0][i];
        int lo=0,hi=(int)vec[1].size()-1,pos=-1;
        while(lo<=hi){
            int mi=(lo+hi)/2;
            if(vec[1][mi]<val){
                pos=mi;
                lo=mi+1;
            }
            else{
                hi=mi-1;
            }
        }
        if(~pos){
            res^=((pos+1)%2);
        }
    }
    return res;
}

void Sub2(){
//    db(Check(1));
    int64_t ans=0;
    for(int i=0;i<=21;++i){
        if(Check(i)){
            ans+=(int64_t)1<<i;
        }
    }
    cout<<ans;
}

void Gen(){
    srand(time(0));
    freopen("info1cup17_xorsum.inp","w",stdout);
    int n=rand()%5+1;
    cout<<n<<'\n';
    for(int i=1;i<=n;++i){
        cout<<rand()%10+1<<' ';
    }
    exit(0);
}

int main()
{
//    Gen();
//    freopen("info1cup17_xorsum.inp","r",stdin);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	for(int i=1;i<=n;++i){
        cin>>a[i];
	}
//	Sub1();
	Sub2();
    return 0;
}

Compilation message

xorsum.cpp: In function 'int Check(int)':
xorsum.cpp:52:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<vec[0].size();++i){
                 ~^~~~~~~~~~~~~~
xorsum.cpp:69:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<vec[1].size();++i){
                 ~^~~~~~~~~~~~~~
xorsum.cpp:86:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<vec[0].size();++i){
                 ~^~~~~~~~~~~~~~
xorsum.cpp: In function 'void Gen()':
xorsum.cpp:119:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen("info1cup17_xorsum.inp","w",stdout);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1700 ms 16108 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1700 ms 16108 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -