답안 #389574

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
389574 2021-04-14T07:35:26 Z rk42745417 XOR Sum (info1cup17_xorsum) C++17
18 / 100
1600 ms 109816 KB
#include <bits/stdc++.h>
using namespace std;

#define EMT ios::sync_with_stdio(0); cin.tie(0);
using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using ld = long double;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
const double EPS = 1e-9;

const int N = 1e5 + 25, LGN = 31;
struct trie {
	struct node {
		int l, r, cnt;
	} arr[N * LGN];
	int t = 2;
	inline int cnt(int p) { return p ? arr[p].cnt : 0; }
	int insert(int v, int n, int id, int c) {
		if(!id)
			id = t++;
		//cout << "inserting " << n << ' ' << id << '\n';
		if(n == -1) {
			arr[id].cnt += c;
			return id;
		}
		if(v >> n & 1)
			arr[id].r = insert(v, n - 1, arr[id].r, c);
		else
			arr[id].l = insert(v, n - 1, arr[id].l, c);
		arr[id].cnt = cnt(arr[id].l) + cnt(arr[id].r);
		return id;
	}
	int que(int v, int n, int tar, int id) {
		if(!id)
			return 0;
		//cout << "owo " << tar << ' ' << id << '\n';
		if(v >> tar & 1) {
			if(n == -1)
				return arr[id].cnt;
			if(v >> n & 1) {
				return que(v, n - 1, tar, arr[id].l);
			}
			else {
				return cnt(arr[id].l) + que(v | (1 << n), n - 1, tar, arr[id].r);
			}
		}
		else {
			if(n == -1)
				return 0;
			if(v >> n & 1) {
				return que(v, n - 1, tar, arr[id].l) + cnt(arr[id].r);
			}
			else {
				return que(v | (1 << n), n - 1, tar, arr[id].r);
			}
		}
	}
	inline int query(int v, int tar) {
		//cout << "here " << v << ' ' << tar << ' ' << arr[1].l << '\n';
		return que(v, tar - 1, tar, arr[1].l) + que(v ^ (1 << tar), tar - 1, tar, arr[1].r);
	}
} tri[LGN];

signed main() {
	int n;
	cin >> n;
	map<int, int> num;
	for(int i = 0, x; i < n; i++) {
		cin >> x;
		num[x]++;
	}
	int ans = 0;
	for(const auto &[v, cnt] : num) {
		if(cnt & 1) {
			///*
			for(int i = 0; i < LGN; i++) {
				int w = tri[i].query(v, i);
				//cout << v << ' ' << i << ' ' << w << '\n';
				if(w & 1)
					ans ^= 1 << i;
			}
			//*/
		}
		for(int i = 0; i < LGN; i++)
			tri[i].insert(v, i, 1, cnt);
		if(1LL * cnt * (cnt + 1) / 2 % 2)
			ans ^= v + v;
	}
	cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 10632 KB Output is correct
2 Correct 90 ms 10572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 388 ms 2764 KB Output is correct
2 Correct 364 ms 2768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 388 ms 2764 KB Output is correct
2 Correct 364 ms 2768 KB Output is correct
3 Execution timed out 1664 ms 54004 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 10632 KB Output is correct
2 Correct 90 ms 10572 KB Output is correct
3 Execution timed out 1679 ms 109816 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 10632 KB Output is correct
2 Correct 90 ms 10572 KB Output is correct
3 Correct 388 ms 2764 KB Output is correct
4 Correct 364 ms 2768 KB Output is correct
5 Execution timed out 1664 ms 54004 KB Time limit exceeded
6 Halted 0 ms 0 KB -