結果
問題 | No.1240 Or Sum of Xor Pair |
ユーザー | tokusakurai |
提出日時 | 2020-09-25 23:22:27 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 4,045 bytes |
コンパイル時間 | 2,332 ms |
コンパイル使用メモリ | 215,644 KB |
実行使用メモリ | 65,208 KB |
最終ジャッジ日時 | 2024-06-28 07:26:54 |
合計ジャッジ時間 | 9,457 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
13,756 KB |
testcase_01 | AC | 3 ms
6,940 KB |
testcase_02 | AC | 4 ms
6,940 KB |
testcase_03 | AC | 59 ms
6,944 KB |
testcase_04 | AC | 52 ms
6,940 KB |
testcase_05 | AC | 55 ms
6,940 KB |
testcase_06 | AC | 34 ms
6,944 KB |
testcase_07 | AC | 34 ms
6,940 KB |
testcase_08 | AC | 32 ms
6,940 KB |
testcase_09 | AC | 43 ms
6,940 KB |
testcase_10 | AC | 344 ms
11,136 KB |
testcase_11 | AC | 410 ms
11,008 KB |
testcase_12 | AC | 658 ms
17,664 KB |
testcase_13 | AC | 726 ms
17,664 KB |
testcase_14 | AC | 738 ms
17,712 KB |
testcase_15 | TLE | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < n; i++) #define rep2(i, x, n) for(int i = x; i <= n; i++) #define rep3(i, x, n) for(int i = x; i >= n; i--) #define elif else if #define sp(x) fixed << setprecision(x) #define pb push_back #define eb emplace_back #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() using ll = long long; using pii = pair<int, int>; using pil = pair<int, ll>; using pli = pair<ll, int>; using pll = pair<ll, ll>; const int MOD = 1000000007; //const int MOD = 998244353; const int inf = (1<<30)-1; const ll INF = (1LL<<60)-1; const double pi = acos(-1.0); const double EPS = 1e-10; template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;}; template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;}; template<typename Monoid> struct Segment_Tree{ vector<Monoid> seg; const Monoid e; const int n; Monoid f(const Monoid &a, const Monoid &b) const{ Monoid ret(18, 0); rep(i, 18) ret[i] = a[i]+b[i]; return ret; } Segment_Tree(int N, const Monoid &e) : e(e), n(1<<(32-__builtin_clz(N-1))){ seg.assign(2*n, e); } void change(int i, const Monoid &x){ seg[i += n] = x; while(i > 0){ i /= 2; seg[i] = f(seg[2*i], seg[2*i+1]); } } Monoid query(int a, int b, int i, int l, int r) const{ if(a >= r || b <= l) return e; if(a <= l && r <= b) return seg[i]; Monoid vl = query(a, b, 2*i, l, (l+r)/2); Monoid vr = query(a, b, 2*i+1, (l+r)/2, r); return f(vl, vr); } Monoid query(int a, int b) {return query(a, b, 1, 0, n);} bool check(const Monoid &a, const Monoid & b) const {return a <= b;} int find_first(int a, int b, const Monoid &x, int i, int l, int r) const{ if(a >= b || a >= r || b <= l || !check(seg[i], x)) return -1; if(r-l == 1) return l; int m = (l+r)/2; if(b <= m) return find_first(a, b, x, 2*i, l, m); if(a >= m) return find_first(a, b, x, 2*i+1, m, r); int tmp = find_first(a, m, x, 2*i, l, m); return (tmp == -1? find_first(m, b, x, 2*i+1, m, r) : tmp); } int find_first(int a, int b, const Monoid &x) const {return find_first(a, b, x, 1, 0, n);} int find_last(int a, int b, const Monoid &x, int i, int l, int r) const{ if(a >= b || a >= r || b <= l || !check(seg[i], x)) return -1; if(r-l == 1) return l; int m = (l+r)/2; if(b <= m) return find_last(a, b, x, 2*i, l, m); if(a >= m) return find_last(a, b, x, 2*i+1, m, r); int tmp = find_last(m, b, x, 2*i+1, m, r); return (tmp == -1? find_last(a, m, x, 2*i, l, m) : tmp); } int find_last(int a, int b, const Monoid &x) const {return find_last(a, b, x, 1, 0, n);} Monoid operator [] (int i) const {return seg[n+i];} void clear(){ fill(all(seg), e); } }; int main(){ int N, X; cin >> N >> X; ll ans = 0; vector<int> a(N); vector<int> cnt(1<<18, 0); rep(i, N){ cin >> a[i]; ans -= a[i], cnt[a[i]]++; } Segment_Tree<vector<int>> seg(N, vector<int>(18, 0)); sort(all(a)); rep(i, N){ vector<int> tmp(18); rep(j, 18) tmp[j] = (a[i]>>j)&1; seg.change(i, tmp); } rep(i, 1<<18){ if(cnt[i] == 0) continue; int y = 0; rep3(j, 17, 0){ if((X>>j)&1){ if((i>>j)&1) y |= 1<<j; int l = lower_bound(all(a), y)-a.begin(); int r = lower_bound(all(a), y+(1<<j))-a.begin(); vector<int> tmp = seg.query(l, r); rep(k, 18){ if((i>>k)&1) ans += (1LL<<k)*(r-l)*cnt[i]; else ans += (1LL<<k)*tmp[k]*cnt[i]; } y ^= 1<<j; } else{ if((i>>j)&1) y |= 1<<j; } } } cout << ans/2 << endl; }