SHARE
TWEET

Untitled

lalalalalalalaalalla Sep 29th, 2019 75 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. struct help {
  52.     int max, ind;
  53.     help(int max_, int ind_) {
  54.         max = max_;
  55.         ind = ind_;
  56.     }
  57.     help() {
  58.         max = -1;
  59.         ind = -2;
  60.     }
  61. };
  62.  
  63. help merge(help a, help b) {
  64.     help c;
  65.     if (a.max > b.max) {
  66.         c.max = a.max;
  67.         c.ind = a.ind;
  68.     } else if (a.max < b.max) {
  69.         c.max = b.max;
  70.         c.ind = b.ind;
  71.     } else {
  72.         c.max = a.max;
  73.         c.ind = min(a.ind, b.ind);
  74.     }
  75.     return c;
  76. }
  77.  
  78. vector<help> t;
  79. vector<int> a;
  80.  
  81. void build(int v, int l, int r) {
  82.     if (r - l == 1) {
  83.         t[v] = help(a[l], l);
  84.         return;
  85.     }
  86.     int m = (l + r) / 2;
  87.     build(2 * v + 1, l, m);
  88.     build(2 * v + 2, m, r);
  89.     t[v] = merge(t[2 * v + 1], t[2 * v + 2]);
  90. }
  91.  
  92. help get_ans(int v, int l, int r, int pos, int val) {
  93.     if (r - l == 1) {
  94.         if (t[v].max >= val && l >= pos) {
  95.             return t[v];
  96.         } else {
  97.             return help(-1, -2);
  98.         }
  99.     }
  100.     if (r <= pos) {
  101.         return help(-1, -2);
  102.     }
  103.     int m = (l + r) / 2;
  104.     help first = get_ans(2 * v + 1, l, m, pos, val), second = get_ans(2 * v + 2, m, r, pos, val);
  105.     if (first.ind == -2) {
  106.         return second;
  107.     }
  108.     return first;
  109. }
  110.  
  111. void update(int v, int l, int r, int pos, int val) {
  112.     if (r - l == 1) {
  113.         t[v].max = val;
  114.         t[v].ind = pos;
  115.         return;
  116.     }
  117.     int m = (l + r) / 2;
  118.     if (pos < m) {
  119.         update(2 * v + 1, l, m, pos, val);
  120.     } else {
  121.         update(2 * v + 2, m, r, pos, val);
  122.     }
  123.     t[v] = merge(t[2 * v + 1], t[2 * v + 2]);
  124. }
  125.  
  126. signed main() {
  127.     ios_base::sync_with_stdio(0);
  128.     cin.tie(0);
  129.     cout.tie(0);
  130.     freopen("nearandmore.in", "r", stdin);
  131.     freopen("nearandmore.out", "w", stdout);
  132.     int n, m;
  133.     cin >> n >> m;
  134.     t.resize(4 * n);
  135.     a.resize(n);
  136.     for (int i = 0; i < n; i++) cin >> a[i];
  137.     build(0, 0, n);
  138.     int type, l, r;
  139.     while (m--) {
  140.         cin >> type >> l >> r;
  141.         if (!type) {
  142.             update(0, 0, n, l - 1, r);
  143.         } else {
  144.             cout << get_ans(0, 0, n, l - 1, r).ind + 1 << "\n";
  145.         }
  146.     }
  147. }
  148. /*
  149.  4 5
  150.  1 2 3 4
  151.  1 1 1
  152.  1 1 3
  153.  1 1 5
  154.  0 2 3
  155.  1 1 3
  156. */
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
 
Top