Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. #include <algorithm>
  2. #include <bitset>
  3. #include <cassert>
  4. #include <cctype>
  5. #include <climits>
  6. #include <cmath>
  7. #include <cstdio>
  8. #include <cstdlib>
  9. #include <cstring>
  10. #include <fstream>
  11. #include <iostream>
  12. #include <iomanip>
  13. #include <iterator>
  14. #include <list>
  15. #include <map>
  16. #include <numeric>
  17. #include <queue>
  18. #include <set>
  19. #include <sstream>
  20. #include <stack>
  21. #include <string>
  22. #include <utility>
  23. #include <vector>
  24. #include <ext/pb_ds/assoc_container.hpp>
  25. #include <ext/pb_ds/tree_policy.hpp>
  26.  
  27. using namespace std;
  28. using namespace __gnu_pbds;
  29.  
  30. const double EPS = 1e-9;
  31. const double PI=acos(-1.0);
  32.  
  33. #define READ(f) freopen(f, "r", stdin)
  34. #define WRITE(f) freopen(f, "w", stdout)
  35.  
  36. #define INF 999999999999999
  37. #define pii pair<int, int>
  38. #define ff first
  39. #define ss second
  40. #define ii long long int
  41. #define uii unsigned long long int
  42. #define ui unsigned int
  43. #define MOD 1000000007
  44.  
  45. template< class T > inline T _abs(T n) { return ((n) < 0 ? -(n) : (n)); }
  46. template< class T > inline T _max(T a, T b) { return (!((a)<(b))?(a):(b)); }
  47. template< class T > inline T _min(T a, T b) { return (((a)<(b))?(a):(b)); }
  48. template< class T > inline T _swap(T &a, T &b) { a=a^b;b=a^b;a=a^b;}
  49. template< class T > inline T gcd(T a, T b) { return (b) == 0 ? (a) : gcd((b), ((a) % (b))); }
  50. template< class T > inline T lcm(T a, T b) { return ((a) / gcd((a), (b)) * (b)); }
  51.  
  52.  
  53. //******************DELETE****************
  54.  
  55. #ifdef rafiul41
  56. #define debug(args...) {cerr<<"Debug: "; dbg,args; cerr<<endl;}
  57. #else
  58. #define debug(args...) // Just strip off all debug tokens
  59. #endif
  60.  
  61. struct debugger{
  62. template<typename T> debugger& operator , (const T& v){
  63. cerr<<v<<" ";
  64. return *this;
  65. }
  66. }dbg;
  67.  
  68. int bitOn(int N,int pos)
  69. {
  70. return N=N | (1<<pos);
  71. }
  72. int bitOff(int N,int pos)
  73. {
  74. return N=N & ~(1<<pos);
  75. }
  76. bool bitCheck(int N,int pos)
  77. {
  78. return (bool)(N & (1<<pos));
  79. }
  80.  
  81. ///*******************************************************************************************
  82.  
  83. typedef tree<
  84. int,
  85. null_type,
  86. less<int>,
  87. rb_tree_tag,
  88. tree_order_statistics_node_update>
  89. ordered_set;
  90.  
  91. ordered_set s;
  92.  
  93. int main()
  94. {
  95. #ifdef rafiul41
  96.  
  97. // READ("in.txt");
  98. // WRITE("out.txt");
  99.  
  100. #endif // rafiul41
  101. int q;
  102. scanf("%d",&q);
  103. s.clear();
  104. for(int i=0;i<q;i++)
  105. {
  106. int x;
  107. char z[2];
  108. scanf("%s %d",z,&x);
  109. if(z[0]=='I')
  110. {
  111. s.insert(x);
  112. }
  113. else if(z[0]=='C')
  114. {
  115. //cout<<s.order_of_key(x)<<endl;
  116. printf("%d\n",s.order_of_key(x));
  117. }
  118. else if(z[0]=='K')
  119. {
  120. x--;
  121. if(s.find_by_order(x)==s.end())
  122. {
  123. //cout<<"invalid"<<endl;
  124. printf("invalid\n");
  125. }
  126. else
  127. {
  128. printf("%d\n",*s.find_by_order(x));
  129. //cout<<*s.find_by_order(x)<<endl;
  130. }
  131. }
  132. else
  133. {
  134. s.erase(x);
  135. }
  136. }
  137. return 0;
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement