关于这种新式平衡树(2)
  • 板块灌水区
  • 楼主mediocre_
  • 当前回复5
  • 已保存回复5
  • 发布时间2024/9/10 21:24
  • 上次更新2024/9/11 13:11:00
查看原帖
关于这种新式平衡树(2)
565707
mediocre_楼主2024/9/10 21:24

>>>上一集

#include <bits/stdc++.h>
using namespace std;
struct Treap {
	vector <int> a;
	void insert(int x) {
		a.insert(lower_bound(a.begin(), a.end(), x), x);    // 插入x
	}
	void eraser(int x) {
		a.erase(lower_bound(a.begin(), a.end(), x));    // 删除x
	}
	int rank(int x) {
		return lower_bound(a.begin(), a.end(), x) - a.begin() + 1;    // 查询x的排名
	}
	int rank_at(int x) {
		return a[x - 1];    // 查询排名为x的数
	}
	int lower_bound(int x) {
		return a[lower_bound(a.begin(), a.end(), x) - a.begin() - 1];    // 查询x前驱
	}
	int upper_bound(int x) {
		return a[upper_bound(a.begin(), a.end(), x) - a.begin()];    // 查询x的后继
	}
} ;
Treap a;
int T, opt, x;
int main() {
	scanf("%d", &T);
	while (T--) {
		scanf("%d%d", &opt, &x);
		switch (opt) {
			case 1:
				a.insert(x);
				break;
			case 2:
				a.eraser(x);
				break;
			case 3:
				printf("%d\n", a.rank(x));
				break;
			case 4:
				printf("%d\n", a.rank_at(x));
				break;
			case 5:
				printf("%d\n", a.lower_bound(x));
				break;
			case 6:
				printf("%d\n", a.upper_bound(x));
				break;
		}
	}
	return 0;
}

我就是想把这个封装了怎么就CE了想问问

2024/9/10 21:24
加载中...