欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

bzoj 3224 普通平衡树 vactor的妙用

发布时间:2025/5/22 编程问答 36 豆豆
生活随笔 收集整理的这篇文章主要介绍了 bzoj 3224 普通平衡树 vactor的妙用 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

3224: Tyvj 1728 普通平衡树

Time Limit: 1 Sec  Memory Limit: 256 MB

题目连接

http://www.lydsy.com/JudgeOnline/problem.php?id=3224

Description

您需要写一种数据结构(可参考题目标题),来维护一些数,其中需要提供以下操作:
1. 插入x数
2. 删除x数(若有多个相同的数,因只删除一个)
3. 查询x数的排名(若有多个相同的数,因输出最小的排名)
4. 查询排名为x的数
5. 求x的前驱(前驱定义为小于x,且最大的数)
6. 求x的后继(后继定义为大于x,且最小的数)

Input

第一行为n,表示操作的个数,下面n行每行有两个数opt和x,opt表示操作的序号(1<=opt<=6)

Output

对于操作3,4,5,6每行输出一个数,表示对应答案

Sample Input

10

1 106465

4 1

1 317721

1 460929

1 644985

1 84185

1 89851

6 81968

1 492737

5 493598

Sample Output

106465

84185

492737



HINT

1.n的数据范围:n<=100000

 

2.每个数的数据范围:[-1e7,1e7]

题意

 

题解:

用一个vector来做

虽然感觉用set也行

 

代码:

 

//qscqesze #include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <set> #include <vector> #include <sstream> #include <queue> #include <typeinfo> #include <fstream> #include <map> #include <stack> typedef long long ll; using namespace std; //freopen("D.in","r",stdin); //freopen("D.out","w",stdout); #define sspeed ios_base::sync_with_stdio(0);cin.tie(0) #define maxn 200001 #define mod 10007 #define eps 1e-9 int Num; char CH[20]; //const int inf=0x7fffffff; //无限大 const int inf=0x3f3f3f3f; /*inline void P(int x) {Num=0;if(!x){putchar('0');puts("");return;}while(x>0)CH[++Num]=x%10,x/=10;while(Num)putchar(CH[Num--]+48);puts(""); } */ //************************************************************************************** inline ll read() {int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f; } inline void P(int x) {Num=0;if(!x){putchar('0');puts("");return;}while(x>0)CH[++Num]=x%10,x/=10;while(Num)putchar(CH[Num--]+48);puts(""); }vector<int> q; int main() {int t=read();while(t--){int n=read(),m=read();if(n==1)q.insert(upper_bound(q.begin(),q.end(),m),m);if(n==2)q.erase(lower_bound(q.begin(),q.end(),m));if(n==3)printf("%d\n",lower_bound(q.begin(),q.end(),m)-q.begin()+1);if(n==4)printf("%d\n",q[m-1]);if(n==5)printf("%d\n",*--lower_bound(q.begin(),q.end(),m));if(n==6)printf("%d\n",*upper_bound(q.begin(),q.end(),m));} }

 

转载于:https://www.cnblogs.com/qscqesze/p/4442006.html

总结

以上是生活随笔为你收集整理的bzoj 3224 普通平衡树 vactor的妙用的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。