P3369 【模板】普通平衡树 vector+二分算法

#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
vector <int> a;
vector <int>::iterator ita;
int main()
{
	int q,n,x;
	cin>>n;
	for (int i=0;i<n;i++)
	{
		cin>>q>>x;
		if (q==3)
		{
			ita=lower_bound(a.begin(),a.end(),x);
			cout<<ita-a.begin()+1<<endl;
		}
		else if(q==4)
		{
			cout<<a[x-1]<<endl; 
		}
		else if(q==5)
		{
			ita=lower_bound(a.begin(),a.end(),x);
			if (ita==a.begin())
			{
				cout<<-2147483647<<endl;
			}
			else 
			{
				ita--;
				cout<<*ita<<endl;
			} 
		}
		else if(q==6)
		{
			ita=upper_bound(a.begin(),a.end(),x);
			if (ita==a.end())
			{
				cout<<2147483647<<endl;
			}
			else
			{
				cout<<*ita<<endl;
			}
		}
		else if (q==1) {
			a.insert(upper_bound(a.begin(),a.end(),x),x);
		}
		else
		{
			a.erase(lower_bound(a.begin(),a.end(),x));
		}
	}
}
/*
7
5 3
5 1
5 3
5 2
5 6
5 8
4 4

*/ 
posted @ 2022-03-01 09:03  心悟&&星际  阅读(23)  评论(0编辑  收藏  举报