P3369 [TEMPLATE] Normal Balance Tree (Treap/SBT) (pb_ds), p31_pb_ds
Description
You need to write a data structure (refer to the title of the question) to maintain the number. The following operations are required:
Input/Output Format
Input Format:
The first behavior n indicates the number of operations. Each row in the n rows below has two numbers opt and x, and opt indicates the number of operations (1 <= opt <= 6)
Output Format:
For operations 3, 4, 5, 6, each row outputs a number, indicating the corresponding answer
Input and Output sample input sample #1:
101 1064654 11 3177211 4609291 6449851 841851 898516 819681 4927375 493598
Output sample #1:
10646584185492737
Description
Time-Space limit: 1000 ms, 128 M
1. Data range of n: n <= 100000
2. Data range of each number: [-1e7, 1e7]
Source: Tyvj1728 Formerly known as: normal Balance Tree
Thank you here
When we were decadent, we had nothing to do with pb_ds ,,
Imagine that someone else spent n hours writing a Balance Tree in the test room to tune the Balance Tree, and you got a second of pleasure in five minutes.
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<ext/pb_ds/tree_policy.hpp> 6 #include<ext/pb_ds/assoc_container.hpp> 7 #include<algorithm> 8 #define lli long long 9 using namespace std;10 using namespace __gnu_pbds;11 void read(lli &n)12 {13 char c='+';lli x=0;bool flag=0;14 while(c<'0'||c>'9'){c=getchar();if(c=='-')flag=1;}15 while(c>='0'&&c<='9'){x=x*10+(c-48);c=getchar();}16 flag==1?n=-x:n=x;17 }18 tree<lli,null_type,std::less<lli>,splay_tree_tag,tree_order_statistics_node_update>st;19 int main()20 {21 ios::sync_with_stdio(0);22 lli T;23 lli ans,x,y;24 cin>>T;25 for(lli i=1;i<=T;i++)26 {27 28 //read(x);read(y);29 cin>>x>>y;30 if(x==1) st.insert((y<<20)+i);31 else if(x==2)st.erase(st.lower_bound(y<<20));32 else if(x==3)printf("%lld\n",st.order_of_key(y<<20)+1);33 else34 {35 if(x==4)ans=*st.find_by_order(y-1);36 if(x==5)ans=*--st.lower_bound(y<<20);37 if(x==6)ans=*st.lower_bound((y+1)<<20);38 printf("%lld\n",ans>>20);39 }40 }41 return 0;42 }