답안 #1114381

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1114381 2024-11-18T17:53:16 Z ttamx XOR Sum (info1cup17_xorsum) C++17
100 / 100
437 ms 27240 KB
#include<bits/stdc++.h>

using namespace std;

const int B=1<<30;

int main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    for(auto &x:a){
        cin >> x;
    }
    int ans=0;
    for(int b=1;b<B;b<<=1){
        vector<int> l,r;
        for(auto x:a){
            ((x&b)?r:l).emplace_back(x);
        }
        int c=0;
        int filter=b*2-1;
        auto f=[&](int x){
            return x&(filter);
        };
        for(int t=0;t<2;t++){
            for(int i=l.size()-1,p=0;i>=0;i--){
                while(p<l.size()&&!((f(l[i])+f(l[p]))&b)){
                    p++;
                }
                if(p<=i){
                    c^=(i-p+1)&1;
                }
            }
            swap(l,r);
        }
        for(int i=r.size()-1,p=0;i>=0;i--){
            while(p<l.size()&&((f(r[i])+f(l[p]))&b)){
                p++;
            }
            c^=p&1;
        }
        ans|=c*b;
        l.insert(l.end(),r.begin(),r.end());
        a=move(l);
    }
    cout << ans;
}

Compilation message

xorsum.cpp: In function 'int main()':
xorsum.cpp:28:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |                 while(p<l.size()&&!((f(l[i])+f(l[p]))&b)){
      |                       ~^~~~~~~~~
xorsum.cpp:38:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |             while(p<l.size()&&((f(r[i])+f(l[p]))&b)){
      |                   ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 336 KB Output is correct
2 Correct 3 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 212 ms 19048 KB Output is correct
2 Correct 207 ms 17028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 212 ms 19048 KB Output is correct
2 Correct 207 ms 17028 KB Output is correct
3 Correct 287 ms 19052 KB Output is correct
4 Correct 298 ms 23884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 336 KB Output is correct
2 Correct 3 ms 336 KB Output is correct
3 Correct 47 ms 2408 KB Output is correct
4 Correct 48 ms 3332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 336 KB Output is correct
2 Correct 3 ms 336 KB Output is correct
3 Correct 212 ms 19048 KB Output is correct
4 Correct 207 ms 17028 KB Output is correct
5 Correct 287 ms 19052 KB Output is correct
6 Correct 298 ms 23884 KB Output is correct
7 Correct 47 ms 2408 KB Output is correct
8 Correct 48 ms 3332 KB Output is correct
9 Correct 409 ms 27236 KB Output is correct
10 Correct 424 ms 27240 KB Output is correct
11 Correct 437 ms 27184 KB Output is correct