TIOJ 1305 - 啊嘶起啦集合

Link: http://tioj.ck.tp.edu.tw/problems/1305

練習平衡樹的裸題,不過我用黑魔法把它AC了
使用g++內建的非標準類別tree,使用說明參考: http://blog.csdn.net/nilihan1999/article/details/29858309

一開始WA還不知道為什麼,原來是ask的k有可能 < 1

AC code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include<bits/stdc++.h>
#include<bits/extc++.h>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> t;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);

string s;
while(cin>>s,s!="exit")
{
int n;
cin>>n;
if(s=="insert")
{
if(t.find(n)==t.end())
t.insert(n);
}
else if(s=="remove")
{
auto it=t.find(n);
if(it!=t.end())
t.erase(it);
}
else if(s=="ask")
{
if(n>t.size() || n<1)
cout<<"error\n";
else
cout<<*t.find_by_order(n-1)<<'\n';
}
}
}