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.

99 lines
1.9 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] = min(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] = min(t[v*2], t[v*2+1]) ;
  48. }
  49. L get(int v, int tl, int tr, int l, int r)
  50. {
  51. if(l <= tl && tr <= r)
  52. return t[v] ;
  53. if(l > tr || r < tl)
  54. return INF ;
  55. int tm = (tl + tr) >> 1 ;
  56. return min(get(v*2, tl, tm, l, r), get(v*2+1, tm+1, tr, l, r)) ;
  57. }
  58. int32_t main(int argc, char *argv[])
  59. {
  60. if(argc > 1)
  61. freopen(argv[1], "r", stdin) ;
  62. //freopen(".in" , "r" , stdin) ;
  63. //freopen(".out" , "w" , stdout) ;
  64. cin >> n >> m ;
  65. for(int i = 0 ; i < n ; ++i)
  66. cin >> a[i] ;
  67. build(1, 0, n-1) ;
  68. while(m--)
  69. {
  70. int type, l, r, x ;
  71. cin >> type ;
  72. if(type == 1)
  73. {
  74. cin >> l >> x ;
  75. update(1, 0, n-1, l, x) ;
  76. }
  77. else
  78. {
  79. cin >> l >> r ;
  80. cout << get(1, 0, n-1, l, r-1) << '\n' ;
  81. }
  82. }
  83. }