fork(2) 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. typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> order_set;
  9.  
  10. order_set X;
  11.  
  12. int get(int y)
  13. {
  14. int l=0,r=1e9+1;
  15. while(l<r)
  16. {
  17. int m=l+((r-l)>>1);
  18. if(m-X.order_of_key(m+1)<y)
  19. l=m+1;
  20. else
  21. r=m;
  22. }
  23. return l;
  24. }
  25.  
  26. main()
  27. {
  28. ios::sync_with_stdio(0);
  29. cin.tie(0);
  30. int n,m;
  31. cin>>n>>m;
  32.  
  33. for(int i=0;i<m;i++)
  34. {
  35. char a;
  36. int b;
  37. cin>>a>>b;
  38. if(a=='L')
  39. cout<<get(b)<<endl;
  40. else
  41. X.insert(get(b));
  42. }
  43. }
Success #stdin #stdout 0s 3476KB
stdin
20 7
L 5
D 5
L 4
L 5
D 5
L 4
L 5
stdout
5
4
6
4
7