SHARE
TWEET

Untitled

lalalalalalalaalalla Oct 3rd, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <iomanip>
  5. #include <queue>
  6. #include <cmath>
  7. #include <algorithm>
  8. #include <tuple>
  9. #include <iomanip>
  10. #include <stdio.h>
  11. #include <numeric>
  12. #include <map>
  13. #include <bitset>
  14. #include <set>
  15. #include <stack>
  16. #include <queue>
  17.  
  18.  
  19. #pragma GCC optimize("Ofast,no-stack-protector")
  20. #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
  21. #pragma GCC optimize("unroll-loops")
  22. #pragma GCC optimize("fast-math")
  23. #pragma GCC optimize("section-anchors")
  24. #pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
  25. #pragma GCC optimize("vpt")
  26. #pragma GCC optimize("rename-registers")
  27. #pragma GCC optimize("move-loop-invariants")
  28. #pragma GCC optimize("unswitch-loops")
  29. #pragma GCC optimize("function-sections")
  30. #pragma GCC optimize("data-sections")
  31. #pragma GCC optimize("branch-target-load-optimize")
  32. #pragma GCC optimize("branch-target-load-optimize2")
  33. #pragma GCC optimize("btr-bb-exclusive")
  34.  
  35.  
  36. //#define int long long
  37. #define ll long long
  38. #define ull unsigned long long
  39. #define all(a) a.begin(), a.end()
  40. #define pii pair<int, int>
  41. #define pb push_back
  42. #define ld long double
  43.  
  44.  
  45. using namespace std;
  46.  
  47. //const int INF = 1e13;
  48. //const int mod = 2600000069;
  49. //const int p = 179;
  50.  
  51. const int MAXN = 200001;
  52.  
  53. int a[MAXN], t[MAXN*4];
  54.  
  55. void build(int v, int l, int r) {
  56.     if (r - l == 1) {
  57.         t[v] = a[l];
  58.         return;
  59.     }
  60.     int m = (l + r) / 2;
  61.     build(2 * v + 1, l, m);
  62.     build(2 * v + 2, m, r);
  63.     t[v] = max(t[(v<<1) + 1], t[(v<<1) + 2]);
  64. }
  65.  
  66. int get_ans(int v, int l, int r, int pos, int val) {
  67.     if (r - l == 1) {
  68.         if (t[v] < val || l < pos) {
  69.             return -2;
  70.         } else {
  71.             return l;
  72.         }
  73.     }
  74.     if (r <= pos) {
  75.         return -2;
  76.     }
  77.     int m = (l + r) / 2;
  78.     int first = get_ans((v<<1) + 1, l, m, pos, val), second = get_ans((v<<1) + 2, m, r, pos, val);
  79.     if (first != -2) {
  80.         return first;
  81.     }
  82.     return second;
  83. }
  84.  
  85. void update(int v, int l, int r, int pos, int val) {
  86.     if (r - l == 1) {
  87.         t[v] = val;
  88.         return;
  89.     }
  90.     int m = (l + r) / 2;
  91.     if (pos < m) {
  92.         update((v<<1) + 1, l, m, pos, val);
  93.     } else {
  94.         update((v<<1) + 2, m, r, pos, val);
  95.     }
  96.     t[v] = max(t[(v<<1) + 1], t[(v<<1) + 2]);
  97. }
  98.  
  99. signed main() {
  100.     ios_base::sync_with_stdio(0);
  101.     cin.tie(0);
  102.     cout.tie(0);
  103.     freopen("nearandmore.in", "r", stdin);
  104.     freopen("nearandmore.out", "w", stdout);
  105.     int n, m;
  106.     cin >> n >> m;
  107.     for (int i = 0; i < n; i++) cin >> a[i];
  108.     build(0, 0, n);
  109.     int type, l, r;
  110.     for (int i = 0; i < m; ++i) {
  111.         cin >> type >> l >> r;
  112.         if (type) {
  113.             cout << get_ans(0, 0, n, l - 1, r) + 1 << "\n";
  114.         } else {
  115.             update(0, 0, n, l - 1, r);
  116.         }
  117.     }
  118. }
  119. /*
  120.  4 5
  121.  1 2 3 4
  122.  1 1 1
  123.  1 1 3
  124.  1 1 5
  125.  0 2 3
  126.  1 1 3
  127. */
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top