fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. // * No One Dies a Virgin, Life Fucks Us All
  4. typedef long long ll;
  5. #define nl '\n'
  6. #define ff first
  7. #define ss second
  8. #define pb push_back
  9. #define sik(x) {cout << x << nl; return;}
  10. constexpr ll maxn = 1e6+10, mod = 1e9 + 7, inf = 1e10, SQ = 450, P = 6065621, maxlg = 20;
  11. typedef pair<ll, ll> pii;
  12.  
  13. ll n, q, a[maxn], seg[maxn << 2];
  14.  
  15. void build(ll l = 1, ll r = n+1, ll id = 1) {
  16. if (r - l <= 1) {
  17. seg[id] = inf;
  18. return;
  19. }
  20. ll mid = (l + r) >> 1, lc = id << 1, rc = lc | 1;
  21. build(l, mid, lc);
  22. build(mid, r, rc);
  23. seg[id] = inf;
  24. }
  25.  
  26. void update(ll ql, ll qr, ll v, ll l = 1, ll r = n+1, ll id = 1) {
  27. if (qr <= l || r <= ql) return;
  28. if (ql <= l && r <= qr) {
  29. seg[id] = min(seg[id], v);
  30. return;
  31. }
  32. ll mid = (l + r) >> 1, lc = id << 1, rc = lc | 1;
  33. update(ql, qr, v, l, mid, lc);
  34. update(ql, qr, v, mid, r, rc);
  35. }
  36.  
  37. ll get(ll ql, ll l = 1, ll r = n+1, ll id = 1) {
  38. if (r - l <= 1) return seg[id];
  39.  
  40. ll mid = (l + r) >> 1, lc = id << 1, rc = lc | 1;
  41. if (ql < mid) return min(seg[id], get(ql, l, mid, lc));
  42. else return min(seg[id], get(ql, mid, r, rc));
  43. }
  44.  
  45. int32_t main() {
  46. cin.tie(0)->sync_with_stdio(0);
  47. cin >> n >> q;
  48. for (int i = 1 ; i <= n ; i ++) cin >> a[i];
  49. build();
  50.  
  51. for (ll t, l, r, x ; q -- ; ) {
  52. cin >> t;
  53. if (t == 1) {
  54. cin >> l >> r >> x, r ++;
  55. update(l, r, x);
  56. } else {
  57. cin >> x;
  58. cout << "-- " << min(a[x], get(x)) << nl;
  59. }
  60. }
  61. cout << nl;
  62. }
Success #stdin #stdout 0s 5644KB
stdin
5 7
1 2 3 4 5
2 2
1 2 4 3
2 2
2 3
2 4
1 3 5 1
2 5
stdout
-- 2
-- 2
-- 3
-- 3
-- 1