Advertisement
SorahISA

TPOJ 1004 (CE)

Mar 7th, 2020
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.51 KB | None | 0 0
  1. // #pragma GCC target("avx2")
  2. #pragma GCC optimize("O3", "unroll-loops")
  3.  
  4. // #include <bits/extc++.h>
  5. // using namespace __gnu_pbds;
  6.  
  7. #include <bits/stdc++.h>
  8. using namespace std;
  9.  
  10. #define int long long
  11. // template <typename T>
  12. // using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  13.  
  14. #define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
  15. #define RANDOM() random_device __rd; \
  16.                  mt19937 __gen = mt19937(__rd()); \
  17.                  uniform_int_distribution<int> __dis(0, INT_MAX); \
  18.                  auto rnd = bind(__dis, __gen);
  19.  
  20. const int mod = 1E9 + 7;
  21. const int maxn = 1 << 18;
  22.  
  23. int zkw[2 * maxn];
  24.  
  25. int Query(int qL, int qR, int ans = 0) {
  26.     ans = min(zkw[qL += maxn], zkw[qR += maxn]);
  27.     while ((qL >> 1) ^ (qR >> 1)) {
  28.         if (~qL & 1) ans = min(ans, zkw[qL^1]);
  29.         if ( qR & 1) ans = min(ans, zkw[qR^1]);
  30.         qL >>= 1, qR >>= 1;
  31.     }
  32.     return ans;
  33. }
  34.  
  35. void Modify(int x, int val) {
  36.     zkw[x += maxn] = val;
  37.     while (x >>= 1) zkw[x] = min(zkw[x<<1], zkw[x<<1|1]);
  38. }
  39.  
  40. void Build(int n) {
  41.     for (int i = 0; i < n; ++i) cin >> zkw[maxn + i];
  42.     for (int i = maxn-1; i >= 1; --i) zkw[i] = min(zkw[i<<1], zkw[i<<1|1]);
  43. }
  44.  
  45. int32_t main() {
  46.     fastIO();
  47.    
  48.     int n, q, x, y;
  49.     char c;
  50.     cin >> n >> q;
  51.    
  52.     Build(n);
  53.    
  54.     while (q--) {
  55.         cin >> c >> x >> y;
  56.         if (c == 'M') Modify(x, y);
  57.         else cout << Query(x, y) << "\n";
  58.     }
  59.    
  60.     return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement