fork download
  1. /*
  2.   author : [ Godsent ]
  3.   created : 2025.08.09 23:29:14
  4. */
  5.  
  6. #include <bits/stdc++.h>
  7.  
  8. #include <ext/pb_ds/assoc_container.hpp>
  9. #include <ext/pb_ds/tree_policy.hpp>
  10. #define el "\n"
  11. #define int long long
  12. #define lb lower_bound
  13. #define ub upper_bound
  14. #define fi first
  15. #define se second
  16. #define sz(x) ((int)(x).size())
  17. #define all(v) (v).begin(), (v).end()
  18. #define pb push_back
  19. #define prs(n) fixed << setprecision(n)
  20.  
  21. const int mod = 1e9 + 7;
  22. const int N = 2e5 + 5;
  23. const int INF = 1e18;
  24.  
  25. using namespace std;
  26. using namespace __gnu_pbds;
  27. template <typename T>
  28. using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  29.  
  30. int q;
  31. ordered_set<pair<int, int>> s;
  32. map<int, int> mp;
  33. int idx = 0;
  34.  
  35. signed main() {
  36. ios_base::sync_with_stdio(false);
  37. cin.tie(0);
  38. cout.tie(0);
  39.  
  40. #ifndef ONLINE_JUDGE
  41. freopen("test.inp", "r", stdin);
  42. freopen("test.out", "w", stdout);
  43. #endif
  44.  
  45. cin >> q;
  46. while (q--) {
  47. int type, x, k;
  48. cin >> type;
  49. if (type == 1) {
  50. cin >> x;
  51. s.insert({x, idx++});
  52. } else if (type == 2) {
  53. cin >> x >> k;
  54. int pos = s.order_of_key({x + 1, -1});
  55. if (pos < k) cout << -1 << el;
  56. else {
  57. auto it = s.find_by_order(pos - k);
  58. cout << it->fi << el;
  59. }
  60. } else {
  61. cin >> x >> k;
  62. int pos = s.order_of_key({x, -1});
  63. if (sz(s) - pos < k) cout << -1 << el;
  64. else {
  65. auto it = s.find_by_order(pos + k - 1);
  66. cout << it->fi << el;
  67. }
  68. }
  69. }
  70.  
  71. // for (auto val : s) cout << val.fi << " ";
  72.  
  73. return 0;
  74. }
  75.  
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
Standard output is empty