답안 #389294

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
389294 2021-04-14T02:22:24 Z i_am_noob XOR Sum (info1cup17_xorsum) C++17
100 / 100
949 ms 40860 KB
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define int ll
#define rep(n) rep1(i,n)
#define rep1(i,n) rep2(i,0,n)
#define rep2(i,a,b) for(int i=a; i<(b); ++i)
#define rep3(i,a,b) for(int i=a; i>=(b); --i)
#define pb push_back
#define pii pair<int,int>
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define pow2(x) (1ll<<(x))

#ifdef i_am_noob
#define bug(...) cerr << "#" << __LINE__ << " " << #__VA_ARGS__ << "- ", _do(__VA_ARGS__)
template<typename T> void _do(T x){cerr << x << endl;}
template<typename T, typename ...S> void _do(T x, S... y){cerr << x << ", ";_do(y...);}
#else
#define bug(...) 49
#endif

const int maxn=1000005;

int n,a[maxn],ans,cur;
vector<int> vec[2];

signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    cin >> n;
    rep(n) cin >> a[i];
    rep(n) vec[a[i]&1].pb(a[i]);
    rep1(j,30){
        int cnt=0;
        bug(j);
        for(auto i: vec[0]) bug(i);
        for(auto i: vec[1]) bug(i);
        rep1(k,2){
            cur=sz(vec[k])-1;
            rep(sz(vec[k])){
                while(cur>=0&&((vec[k][i]+vec[k][cur])>>j&1)) cur--;
                cnt+=sz(vec[k])-1-cur;
                //if((sz(vec[k])-1-cur)&1) ans^=pow2(j);
            }
        }
        rep(n) if((a[i]<<1)&pow2(j)) cnt++;
        cnt/=2;
        if(cnt&1) ans^=pow2(j);
        cur=0;
        rep3(i,sz(vec[0])-1,0){
            while(cur<sz(vec[1])&&((vec[0][i]+vec[1][cur])>>j&1)) cur++;
            if(cur&1) ans^=pow2(j);
        }
        vector<int> tmp[2];
        for(auto i: vec[0]) if(!(i&pow2(j+1))) tmp[0].pb(i);
        for(auto i: vec[1]) if(!(i&pow2(j+1))) tmp[0].pb(i);
        for(auto i: vec[0]) if(i&pow2(j+1)) tmp[1].pb(i);
        for(auto i: vec[1]) if(i&pow2(j+1)) tmp[1].pb(i);
        vec[0]=tmp[0],vec[1]=tmp[1];
    }
    cout << ans << "\n";
}

Compilation message

xorsum.cpp: In function 'int main()':
xorsum.cpp:21:18: warning: statement has no effect [-Wunused-value]
   21 | #define bug(...) 49
      |                  ^~
xorsum.cpp:36:9: note: in expansion of macro 'bug'
   36 |         bug(j);
      |         ^~~
xorsum.cpp:21:18: warning: statement has no effect [-Wunused-value]
   21 | #define bug(...) 49
      |                  ^~
xorsum.cpp:37:29: note: in expansion of macro 'bug'
   37 |         for(auto i: vec[0]) bug(i);
      |                             ^~~
xorsum.cpp:37:18: warning: unused variable 'i' [-Wunused-variable]
   37 |         for(auto i: vec[0]) bug(i);
      |                  ^
xorsum.cpp:21:18: warning: statement has no effect [-Wunused-value]
   21 | #define bug(...) 49
      |                  ^~
xorsum.cpp:38:29: note: in expansion of macro 'bug'
   38 |         for(auto i: vec[1]) bug(i);
      |                             ^~~
xorsum.cpp:38:18: warning: unused variable 'i' [-Wunused-variable]
   38 |         for(auto i: vec[1]) bug(i);
      |                  ^
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 460 KB Output is correct
2 Correct 5 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 627 ms 37912 KB Output is correct
2 Correct 577 ms 35932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 627 ms 37912 KB Output is correct
2 Correct 577 ms 35932 KB Output is correct
3 Correct 763 ms 37908 KB Output is correct
4 Correct 711 ms 36860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 460 KB Output is correct
2 Correct 5 ms 460 KB Output is correct
3 Correct 106 ms 4200 KB Output is correct
4 Correct 92 ms 4204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 460 KB Output is correct
2 Correct 5 ms 460 KB Output is correct
3 Correct 627 ms 37912 KB Output is correct
4 Correct 577 ms 35932 KB Output is correct
5 Correct 763 ms 37908 KB Output is correct
6 Correct 711 ms 36860 KB Output is correct
7 Correct 106 ms 4200 KB Output is correct
8 Correct 92 ms 4204 KB Output is correct
9 Correct 949 ms 40760 KB Output is correct
10 Correct 916 ms 40860 KB Output is correct
11 Correct 909 ms 40796 KB Output is correct