# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
215972 | 2020-03-26T13:25:23 Z | wendy_virgo | XOR Sum (info1cup17_xorsum) | C++14 | 1600 ms | 17184 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; #define int64_t int int n; int64_t a[N],b[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'; } void Sort(int pos){ vector<int> freq(2); for(int i=1;i<=n;++i){ freq[(a[i]>>pos)&(int64_t)1]++; } freq[1]+=freq[0]; for(int i=n;i>=1;--i){ int id=(a[i]>>pos)&(int64_t)1; b[freq[id]]=a[i]; freq[id]--; } for(int i=1;i<=n;++i){ a[i]=b[i]; } } int Check(int pos){ int res=0; vector<vector<int64_t>> vec(2); for(int i=1;i<=n;++i){ int64_t val=0; for(int j=0;j<pos;++j){ if((a[i]>>j)&(int64_t)1){ val|=(int64_t)1<<j; } } vec[(a[i]>>pos)&1].push_back(val); } // assert(is_sorted(begin(vec[0]),end(vec[0]))); // assert(is_sorted(begin(vec[1]),end(vec[1]))); int ptr=(int)vec[0].size()-1; int ptr1=(int)vec[1].size()-1; for(int i=0;i<vec[0].size();++i){ int64_t val=((int64_t)1<<pos)-vec[0][i]; while(ptr>=0&&vec[0][ptr]>=val){ ptr--; } if(ptr+1<=i){ res^=(i-(ptr+1)+1)%2; } int64_t val1=((int64_t)1<<pos)-vec[0][i]; while(ptr1>=0&&vec[1][ptr1]>=val1){ ptr1--; } res^=(ptr1+1)%2; } ptr=(int)vec[1].size()-1; for(int i=0;i<vec[1].size();++i){ int64_t val=((int64_t)1<<pos)-vec[1][i]; while(ptr>=0&&vec[1][ptr]>=val){ ptr--; } if(ptr+1<=i){ res^=(i-(ptr+1)+1)%2; } } Sort(pos); return res; } void Sub2(){ int64_t ans=0; for(int i=0;i<=30;++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); } inline int ReadInt() { char c; int sign = 1; for (c = getchar(); c < '0' || c > '9'; c = getchar()) if (c == '-') sign = -sign; int res = c - '0'; for (c = getchar(); c >= '0' && c <= '9'; c = getchar()) res = res * 10 + c - '0'; return res * sign; } int32_t main() { // Gen(); // freopen("info1cup17_xorsum.inp","r",stdin); // freopen("info1cup17_xorsum.out","w",stdout); ios_base::sync_with_stdio(0); cin.tie(0); n=ReadInt(); for(int i=1;i<=n;++i){ a[i]=ReadInt(); } // Sub1(); Sub2(); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 384 KB | Output is correct |
2 | Correct | 16 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1146 ms | 17184 KB | Output is correct |
2 | Correct | 1064 ms | 15600 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1146 ms | 17184 KB | Output is correct |
2 | Correct | 1064 ms | 15600 KB | Output is correct |
3 | Execution timed out | 1664 ms | 16836 KB | Time limit exceeded |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 384 KB | Output is correct |
2 | Correct | 16 ms | 384 KB | Output is correct |
3 | Correct | 240 ms | 2108 KB | Output is correct |
4 | Correct | 245 ms | 2200 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 384 KB | Output is correct |
2 | Correct | 16 ms | 384 KB | Output is correct |
3 | Correct | 1146 ms | 17184 KB | Output is correct |
4 | Correct | 1064 ms | 15600 KB | Output is correct |
5 | Execution timed out | 1664 ms | 16836 KB | Time limit exceeded |
6 | Halted | 0 ms | 0 KB | - |