結果

問題 No.1240 Or Sum of Xor Pair
ユーザー SHIJOUSHIJOU
提出日時 2020-09-26 18:09:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,461 bytes
コンパイル時間 2,322 ms
コンパイル使用メモリ 210,764 KB
実行使用メモリ 60,496 KB
最終ジャッジ日時 2023-09-11 23:15:31
合計ジャッジ時間 17,511 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
60,276 KB
testcase_01 AC 56 ms
60,400 KB
testcase_02 AC 54 ms
60,404 KB
testcase_03 AC 70 ms
60,340 KB
testcase_04 AC 71 ms
60,152 KB
testcase_05 AC 72 ms
60,152 KB
testcase_06 AC 67 ms
60,176 KB
testcase_07 AC 66 ms
60,420 KB
testcase_08 AC 64 ms
60,212 KB
testcase_09 AC 69 ms
60,224 KB
testcase_10 AC 141 ms
60,400 KB
testcase_11 AC 146 ms
60,292 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 57 ms
60,396 KB
testcase_28 AC 57 ms
60,152 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<ll, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0xccccccc;
const ll LINF = 0xcccccccccccccccLL;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}


struct SegTree {
	struct node {
		int sum;
		vector<int> cc;
		node():sum(0), cc(18) {}
		int &operator[] (int i) {return cc[i];}
	};
	using T = node;
	int n, _n;
	const T ex;
	vector<T> dat;
	SegTree(T ex_ = node()):ex(ex_), n(1<<18) {
		dat.assign((n<<1)-1, ex);
	}
	inline int chld(int k) {return (k<<1)+1;}
	inline int chrd(int k) {return (k<<1)+2;}
	inline ll query(int a, int x) {return query(a, x, 17, 0, 0, n);}
	ll query(int a, int x, int z, int k, int l, int r) {
		if(l >= x) return 0;
		if(r <= x) {
			ll res = 0;
			rep(i, 18) {
				if(a>>i&1) res += dat[k].sum * (1<<i);
				else res += dat[k][i] * (1<<i);
			}
			return res;
		}
		ll vl = query(a, x, z-1, (~a>>z&1)?chld(k):chrd(k), l, (l+r)>>1);
		ll vr = query(a, x, z-1, (~a>>z&1)?chrd(k):chld(k), (l+r)>>1, r);
		return vl + vr;
	}
	void update(int a) {update(a, 0, 0, n);}
	void update(int a,int k, int l, int r) {
		if(r-l == 1) {
			dat[k].sum++;
			rep(j, 18) if(a>>j&1) {
				dat[k][j]++;
			}
		}
		else {
			if(a < ((l+r)>>1)) update(a, chld(k), l, (l+r)>>1);
			else update(a, chrd(k), (l+r)>>1, r);
			T &c = dat[k];
			c.sum++;
			rep(i, 18) if(a>>i&1) c[i]++;
		}
	}
	const T &operator[](int idx) const {return dat[idx+n-1];}
	T &operator[](int idx) {return dat[idx+n-1];}
};

#define N 200100

//head

int n, x;
SegTree seg;
ll ans;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> x;
	rep(i, n) {
		int a;
		cin >> a;
		ans += seg.query(a, x);
		seg.update(a);
	}
	cout << ans << endl;
}
0