bzoj 3224 普通平衡树 vactor的妙用
生活随笔
收集整理的這篇文章主要介紹了
bzoj 3224 普通平衡树 vactor的妙用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
3224: Tyvj 1728 普通平衡樹
Time Limit: 1 Sec??Memory Limit: 256 MB
題目連接
http://www.lydsy.com/JudgeOnline/problem.php?id=3224Description
您需要寫一種數據結構(可參考題目標題),來維護一些數,其中需要提供以下操作: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
101 106465
4 1
1 317721
1 460929
1 644985
1 84185
1 89851
6 81968
1 492737
5 493598
Sample Output
10646584185
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的妙用的全部內容,希望文章能夠幫你解決所遇到的問題。