fork download
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4.  
  5. using namespace std;
  6. using namespace __gnu_pbds;
  7.  
  8. int main(){
  9. tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> tr;
  10. long long n,q,el=0;
  11. cin >> n >> q;
  12. while(q--){
  13. long long t,v;
  14. cin >> t >> v;
  15. if(t==1){
  16. tr.insert(v);
  17. el++;
  18. }
  19. else{
  20. long long st=v,fi=v+el,te;
  21. while(st<=fi){
  22. te=(st+fi)/2;
  23. if((te-tr.order_of_key(te+1))<v){st=te+1;}
  24. else{fi=te-1;}
  25. }
  26. cout << st << '\n';
  27. }
  28. }
  29. return 0;
  30. }
Success #stdin #stdout 0s 4356KB
stdin
1000000000000000000 9
2 8
1 6
2 8
1 1
2 2
1 9
2 7
1 999999999999999999
2 999999999999999996
stdout
8
9
3
10
1000000000000000000