Advertisement
lalalalalalalaalalla

Untitled

Oct 5th, 2019
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  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. vector<int> a, t;
  52.  
  53. void build(int v, int l, int r) {
  54. if (r - l == 1) {
  55. t[v] = a[l];
  56. return;
  57. }
  58. int m = (l + r) / 2;
  59. build(2 * v + 1, l, m);
  60. build(2 * v + 2, m, r);
  61. t[v] = max(t[2 * v + 1], t[2 * v + 2]);
  62. }
  63.  
  64. int get_ans(int v, int l, int r, int pos, int val) {
  65. if (r - l == 1) {
  66. if (t[v] >= val && l >= pos) {
  67. return l;
  68. } else {
  69. return -2;
  70. }
  71. }
  72. if (r <= pos) {
  73. return -2;
  74. }
  75. int m = (l + r) / 2;
  76. int first = get_ans(2 * v + 1, l, m, pos, val), second = get_ans(2 * v + 2, m, r, pos, val);
  77. if (first == -2) {
  78. return second;
  79. }
  80. return first;
  81. }
  82.  
  83. void update(int v, int l, int r, int pos, int val) {
  84. if (r - l == 1) {
  85. t[v] = val;
  86. return;
  87. }
  88. int m = (l + r) / 2;
  89. if (pos < m) {
  90. update(2 * v + 1, l, m, pos, val);
  91. } else {
  92. update(2 * v + 2, m, r, pos, val);
  93. }
  94. t[v] = max(t[2 * v + 1], t[2 * v + 2]);
  95. }
  96.  
  97. signed main() {
  98. ios_base::sync_with_stdio(0);
  99. cin.tie(0);
  100. cout.tie(0);
  101. freopen("nearandmore.in", "r", stdin);
  102. freopen("nearandmore.out", "w", stdout);
  103. int n, m;
  104. cin >> n >> m;
  105. t.resize(4 * n);
  106. a.resize(n);
  107. for (int i = 0; i < n; i++) cin >> a[i];
  108. build(0, 0, n);
  109. int type, l, r;
  110. while (m--) {
  111. cin >> type >> l >> r;
  112. if (!type) {
  113. update(0, 0, n, l - 1, r);
  114. } else {
  115. cout << get_ans(0, 0, n, l - 1, r) + 1 << "\n";
  116. }
  117. }
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement