結果

問題 No.1240 Or Sum of Xor Pair
ユーザー SHIJOUSHIJOU
提出日時 2020-09-26 18:12:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,460 bytes
コンパイル時間 2,368 ms
コンパイル使用メモリ 209,820 KB
実行使用メモリ 60,704 KB
最終ジャッジ日時 2023-09-11 23:21:33
合計ジャッジ時間 17,945 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 WA -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
権限があれば一括ダウンロードができます

ソースコード

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