답안 #918422

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
918422 2024-01-29T19:53:25 Z divad XOR Sum (info1cup17_xorsum) C++14
7 / 100
1600 ms 66996 KB
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
const int NMAX = 1e6+2;
int n,v[NMAX];

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<pair<int, int>, null_type,less<pair<int, int>>, rb_tree_tag,tree_order_statistics_node_update>

const int INF = 1e6;
struct FenwickTree {
    ordered_set s;
    int cnt = 0;
    FenwickTree(){}
    void update(int pos){
        s.insert({pos, ++cnt});
    }
    int query(int pos){
        return s.order_of_key({pos+1, 0});
    }
    int query(int l, int r){
        return query(r) - query(l-1);
    }
};

int brut(int k){
    int ans = 0;
    int mod = (1<<(k+1));
    int l = (1<<k), r = (1<<(k+1))-1;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= i; j++){
            int sum = (v[i]+v[j])%mod;
            int bt = (sum>>k)&1;
            if(bt){
                assert(l <= sum && sum <= r);
            }
            ans += bt;
        }
    }
    return ans;
}

bool inauntru(int x, pii interv){
    auto [l, r] = interv;
    return (l <= x && x <= r);
}

int cnt(int k){
    FenwickTree aib;
    int mod = (1<<(k+1));
    int ans = 0;
    for(int i = 1; i <= n; i++){
        int val = v[i]%mod;
        aib.update(val);
        int l = (1<<k), r = (1<<(k+1))-1;
        l = (l-val+mod)%mod;
        r = (r-val+mod)%mod;
        if(l <= r){
            ans += aib.query(l, r);
        }else{
            ans += aib.query(r);
            ans += aib.query(l, mod-1);
        }
    }
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> v[i];
    }
    int ans = 0;
    for(int i = 0; i < 30; i++){
        ans += (cnt(i)&1)*(1<<i);
    }
    cout << ans;
    return 0;
}

Compilation message

xorsum.cpp: In function 'bool inauntru(int, pii)':
xorsum.cpp:47:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   47 |     auto [l, r] = interv;
      |          ^
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 728 KB Output is correct
2 Correct 38 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1649 ms 66996 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1649 ms 66996 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 728 KB Output is correct
2 Correct 38 ms 604 KB Output is correct
3 Execution timed out 1637 ms 8680 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 728 KB Output is correct
2 Correct 38 ms 604 KB Output is correct
3 Execution timed out 1649 ms 66996 KB Time limit exceeded
4 Halted 0 ms 0 KB -