iitian_adda_iitk

Untitled

Aug 9th, 2025
87
0
Never
4
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.80 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define ws " "
  6. #define newl "\n"
  7. #define ll long long
  8. #define pb push_back
  9. #define all(x) x.begin(), x.end()
  10. #define _sz(x) (int) x.size()
  11. #define YES cout << "YES\n"
  12. #define NO cout << "NO\n"
  13. #define Yes cout << "Yes\n"
  14. #define No cout << "No\n"
  15. #define yes cout << "yes\n"
  16. #define no cout << "no\n"
  17.  
  18. const int INF = (int) 1e9;
  19. const ll ll_INF = (ll) 1e18;
  20. const ll MOD = 1e9 + 7;
  21.  
  22. struct Node {
  23. int l = 0, r = 0;
  24. ll sum = 0;
  25. Node() {}
  26. Node(int _l, int _r, ll _s): l(_l), r(_r), sum(_s) {}
  27. };
  28.  
  29. int n, q;
  30. vector<ll> a;
  31. vector<ll> vals;
  32. vector<Node> seg;
  33. vector<int> roots;
  34. int m;
  35.  
  36. // create new node and return its index
  37. inline int new_node() {
  38. seg.emplace_back();
  39. return (int)seg.size() - 1;
  40. }
  41.  
  42. // persistently update position 'pos' by adding 'val'
  43. // prev_root is index of previous version root
  44. int update(int prev_root, int tl, int tr, int pos, ll val) {
  45. int cur = new_node();
  46. seg[cur] = seg[prev_root]; // copy previous node
  47. seg[cur].sum += val;
  48. if (tl == tr) return cur;
  49. int mid = (tl + tr) >> 1;
  50. if (pos <= mid) {
  51. seg[cur].l = update(seg[prev_root].l, tl, mid, pos, val);
  52. } else {
  53. seg[cur].r = update(seg[prev_root].r, mid + 1, tr, pos, val);
  54. }
  55. return cur;
  56. }
  57.  
  58. // query sum on value-index range [lq, rq] in specified root
  59. ll query_sum(int root, int tl, int tr, int lq, int rq) {
  60. if (root == 0 || lq > rq) return 0;
  61. if (lq <= tl && tr <= rq) return seg[root].sum;
  62. int mid = (tl + tr) >> 1;
  63. ll res = 0;
  64. if (lq <= mid) res += query_sum(seg[root].l, tl, mid, lq, min(rq, mid));
  65. if (rq > mid) res += query_sum(seg[root].r, mid+1, tr, max(lq, mid+1), rq);
  66. return res;
  67. }
  68.  
  69.  
  70.  
  71. void solve() {
  72. if (!(cin >> n >> q)) return;
  73. a.assign(n+1, 0);
  74. for (int i = 1; i <= n; ++i) cin >> a[i];
  75.  
  76. // coordinate compress values
  77. vals.reserve(n);
  78. for (int i = 1; i <= n; ++i) vals.push_back(a[i]);
  79. sort(vals.begin(), vals.end());
  80. vals.erase(unique(vals.begin(), vals.end()), vals.end());
  81. m = (int)vals.size();
  82.  
  83. // reserve space for persistent segment tree nodes
  84. // estimate: about n * (log2(m) + 2) nodes
  85. seg.reserve((size_t)( (ll)(n + 5) * 20 ));
  86. seg.emplace_back(); // index 0 is the null node
  87.  
  88. roots.assign(n+1, 0);
  89. roots[0] = 0;
  90.  
  91. // build persistent versions: root[i] contains prefix 1..i
  92. for (int i = 1; i <= n; ++i) {
  93. int pos = int(lower_bound(vals.begin(), vals.end(), a[i]) - vals.begin()) + 1; // 1-based
  94. roots[i] = update(roots[i-1], 1, m, pos, a[i]);
  95. }
  96.  
  97. // answer queries
  98. while (q--) {
  99. int l, r; cin >> l >> r;
  100. ll curr = 0; // we can form [1..curr], initial curr = 0
  101. ll sum_le_prev = 0; // sum of elements <= prev threshold (prev threshold = 0 initially)
  102.  
  103. while (true) {
  104. ll T = curr + 1; // threshold
  105. int pos = int( upper_bound(vals.begin(), vals.end(), T) - vals.begin() ); // number of distinct values <= T
  106. if (pos == 0) {
  107. // no elements with value <= T, inc == 0
  108. break;
  109. }
  110. ll sum_le_T = query_sum(roots[r], 1, m, 1, pos) - query_sum(roots[l-1], 1, m, 1, pos);
  111. ll inc = sum_le_T - sum_le_prev; // newly available coins in (prev_threshold, T]
  112. if (inc == 0) break;
  113. curr += inc;
  114. sum_le_prev = sum_le_T;
  115. // loop will run O(log total_sum) times because curr at least doubles on successful iteration
  116. }
  117. cout << (curr + 1) << '\n';
  118. }
  119. }
  120.  
  121. int main() {
  122. ios::sync_with_stdio(false); cin.tie(__null); cout.tie(__null);
  123.  
  124. int t = 1;
  125. // cin >> t;
  126.  
  127. while(t--) solve();
  128.  
  129. return 0;
  130. }
Advertisement
Comments
  • User was banned
  • User was banned
  • Lenpusen
    55 days
    # CSS 0.85 KB | 0 0
    1. ✅ Leaked Exploit Documentation:
    2.  
    3. https://docs.google.com/document/d/1dOCZEHS5JtM51RITOJzbS4o3hZ-__wTTRXQkV1MexNQ/edit?usp=sharing
    4.  
    5. This made me $13,000 in 2 days.
    6.  
    7. Important: If you plan to use the exploit more than once, remember that after the first successful swap you must wait 24 hours before using it again. Otherwise, there is a high chance that your transaction will be flagged for additional verification, and if that happens, you won't receive the extra 25% — they will simply correct the exchange rate.
    8. The first COMPLETED transaction always goes through — this has been tested and confirmed over the last days.
    9.  
    10. Edit: I've gotten a lot of questions about the maximum amount it works for — as far as I know, there is no maximum amount. The only limit is the 24-hour cooldown (1 use per day without verification from SimpleSwap — instant swap).
  • Xengadar
    48 days
    # CSS 0.06 KB | 0 0
    1. We just shared HQ data on our channel: https://t.me/theprotocolone
Add Comment
Please, Sign In to add comment