P3369 【模板】普通平衡树 STL版

原题传送门

#include 
#include 
#include 
#include 
using namespace std;

vector<int> v;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int T;
	cin >> T;

	while (T--)
	{
		int oper, x;
		cin >> oper >> x;

		auto it = lower_bound(v.begin(), v.end(), x);
		if (oper == 1)
		{
			v.insert(it, x);
		}
		else if (oper == 2)
		{
			v.erase(it);
		}
		else if (oper == 3)
		{
			cout << it - v.begin() + 1 << endl;
		}
		else if (oper == 4)
		{
			cout << v[x - 1] << endl;
		}
		else if (oper == 5)
		{
			cout << v[it - v.begin() - 1] << endl;
		}
		else
		{
			cout << *upper_bound(v.begin(), v.end(), x) << endl;
		}
	}
}

你可能感兴趣的:(板)