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