DSA
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
2.1 KiB

  1. /*
  2. #pragma GCC target ("avx2")
  3. #pragma GCC optimize ("Ofast")
  4. #pragma GCC optimize ("unroll-loops")
  5. */
  6. #include "bits/stdc++.h"
  7. #define iosb ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
  8. #define BIT(x) __builtin_popcount(x)
  9. #define all(x) x.begin() , x.end()
  10. #define F first
  11. #define S second
  12. #define pb push_back
  13. using namespace std ;
  14. typedef unsigned long long UL ;
  15. typedef long long L ;
  16. typedef string T ;
  17. typedef int I ;
  18. const I MaxN = 1e5+1 ;
  19. const I MOD = 1e9+7 ;
  20. const I inf = 2e9+7 ;
  21. const L INF = 2e18+7 ;
  22. L t[4*MaxN], mod[4*MaxN], a[MaxN], n, m ;
  23. void build(int v, int tl, int tr)
  24. {
  25. if(tl == tr)
  26. {
  27. t[v] = a[tl] ;
  28. return ;
  29. }
  30. int tm = (tl + tr) >> 1 ;
  31. build(v*2, tl, tm) ;
  32. build(v*2+1, tm+1, tr) ;
  33. t[v] = max(t[v*2], t[v*2+1]) ;
  34. }
  35. void update(int v, int tl, int tr, int l, int x)
  36. {
  37. if(tl == tr && tl == l)
  38. {
  39. t[v] = x ;
  40. return ;
  41. }
  42. if(tr < l || l < tl)
  43. return ;
  44. int tm = (tl + tr) >> 1 ;
  45. update(v*2, tl, tm, l, x) ;
  46. update(v*2+1, tm+1, tr, l, x) ;
  47. t[v] = max(t[v*2], t[v*2+1]) ;
  48. }
  49. int above(int v, int tl, int tr, int l, int x)
  50. {
  51. if(l > tr)
  52. return -1 ;
  53. if(tl == tr)
  54. {
  55. if(x > t[v])
  56. return -1 ;
  57. return tl ;
  58. }
  59. int tm = (tl + tr) >> 1 ;
  60. if(t[v*2] >= x)
  61. {
  62. int ab = above(v*2, tl, tm, l, x) ;
  63. if(ab == -1)
  64. return above(v*2+1, tm+1, tr, l, x) ;
  65. }
  66. else
  67. return above(v*2+1, tm+1, tr, l, x) ;
  68. }
  69. int32_t main(int argc, char *argv[])
  70. {
  71. if(argc > 1)
  72. freopen(argv[1], "r", stdin) ;
  73. //freopen(".in" , "r" , stdin) ;
  74. //freopen(".out" , "w" , stdout) ;
  75. cin >> n >> m ;
  76. for(int i = 0 ; i < n ; ++i)
  77. cin >> a[i] ;
  78. build(1, 0, n-1) ;
  79. while(m--)
  80. {
  81. int type, l, x ;
  82. cin >> type ;
  83. if(type == 1)
  84. {
  85. cin >> l >> x ;
  86. update(1, 0, n-1, l, x) ;
  87. }
  88. else
  89. {
  90. cin >> x >> l ;
  91. cout << above(1, 0, n-1, l, x) << '\n' ;
  92. }
  93. }
  94. }