P6136 求调
  • 板块学术版
  • 楼主蒟蒻Ken_bruce
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/11/6 14:18
  • 上次更新2023/11/6 18:12:16
查看原帖
P6136 求调
302967
蒟蒻Ken_bruce楼主2023/11/6 14:18

用 pbdspbds 做的(普通平衡树已过),44分,玄关。

#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace __gnu_pbds;
tree<long long, null_type, std::less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> t;
tree<long long, null_type, std::less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update>::iterator it;
long long n, i = 1, nn, m;
inline void read(long long& x) {
	x = 0;
	int t = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9') {
		if (ch == '-')
			t = -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9'){
		x = (x << 1) + (x << 3) + (ch ^ 48);
		ch = getchar();
	}
	x *= t;
}
void write(long long x) {
	if (x < 0) {
		putchar('-');
		x = -x;
	}
	if (x > 9) write(x / 10);
	putchar(x % 10 ^ 48);
}
long long ttt, ans, num;
int main() {
//	freopen("P6136_1.in.txt", "r", stdin);
	read(m);
	read(n);
	for(int i = 1; i <= m; i++) {
		read(ttt);
		t.insert(ttt);
	}
	nn = 1e6;
	while(n--) {
		long long id, x;
		read(id);
		read(x);
		if(ans != 0) x ^= ans;
		switch(id) {
			case 1:t.insert(x);break;
			case 2:t.erase(t.lower_bound(x));break;
			case 3:ans = t.order_of_key(x + 1);num ^= ans;break;
			case 4:it = t.find_by_order(x - 1);ans = *it;num ^= ans;break;
			case 5:it = t.lower_bound(x + nn);ans = *it;num ^= ans;break;
			case 6:it = t.upper_bound(x);it--;ans = *it;num ^= ans;break;
		}
		//std::cout << "id: " << id << ' ' << x << " " << ans << " " << num << std::endl;
	}
	write(num);
	return 0;
}
2023/11/6 14:18
加载中...