Algorithm-Library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub UScuber/Algorithm-Library

:heavy_check_mark: test/aoj/DSL/DSL_2_F.test.cpp

Depends on

Code

#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/problems/DSL_2_F"

#include "../../../template/template.hpp"

#include "../../../SegmentTree/rupdate-rmin.hpp"

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n,q;
  cin >> n >> q;
  LazySegmentTree<int,min> seg(n);
  while(q--){
    int t; cin >> t;
    if(t == 0){
      int l,r,x;
      cin >> l >> r >> x;
      seg.update(l, r+1, x);
    }else{
      int l,r;
      cin >> l >> r;
      cout << seg.query(l, r+1) << "\n";
    }
  }
}
#line 1 "test/aoj/DSL/DSL_2_F.test.cpp"
#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/problems/DSL_2_F"

#line 1 "template/template.hpp"
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <bitset>
#include <cctype>
#include <climits>
#include <functional>
#include <cassert>
#include <numeric>
#include <cstring>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define per(i, n) for(int i = (n) - 1; i >= 0; i--)
using ll = long long;
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
constexpr int mod = 1000000007;
using namespace std;
template<class T, class U>
bool chmax(T &a, const U &b){ return a < b ? (a = b, 1) : 0; }
template<class T, class U>
bool chmin(T &a, const U &b){ return a > b ? (a = b, 1) : 0; }
#line 4 "test/aoj/DSL/DSL_2_F.test.cpp"

#line 1 "SegmentTree/rupdate-rmin.hpp"
template <class T, const T&(*op)(const T&,const T&)>
struct LazySegmentTree {
  LazySegmentTree(const int _n) : n(_n){
    while((1 << log) < n) log++;
    len = 1 << log;
    d.assign(len * 2, inf);
    lazy.assign(len, inf);
  }
  void set(const int i, const T &x){
    assert(0 <= i && i < n);
    d[i + len] = x;
  }
  T get(int p){
    assert(0 <= p && p < n);
    p += len;
    for(int i = log; i >= 1; i--) push(p >> i);
    return d[p];
  }
  void build(){
    for(int i = len - 1; i >= 1; i--) update(i);
  }
  void update(int l, int r, const T &x){
    assert(0 <= l && l <= r && r <= n);
    l += len; r += len;
    const int l_ctz = __builtin_ctz(l);
    const int r_ctz = __builtin_ctz(r);
    for(int i = log; i > l_ctz; i--) push(l >> i);
    for(int i = log; i > r_ctz; i--) push((r - 1) >> i);
    const int lt = l, rt = r;
    while(l < r){
      if(l & 1) apply(l++, x);
      if(r & 1) apply(--r, x);
      l >>= 1; r >>= 1;
    }
    l = lt; r = rt;
    for(int i = l_ctz + 1; i <= log; i++) update(l >> i);
    for(int i = r_ctz + 1; i <= log; i++) update((r - 1) >> i);
  }
  T query(int l, int r){
    assert(0 <= l && l <= r && r <= n);
    l += len; r += len;
    const int l_ctz = __builtin_ctz(l);
    const int r_ctz = __builtin_ctz(r);
    for(int i = log; i > l_ctz; i--) push(l >> i);
    for(int i = log; i > r_ctz; i--) push((r - 1) >> i);
    T left = inf, right = inf;
    while(l < r){
      if(l & 1) left = op(left, d[l++]);
      if(r & 1) right = op(d[--r], right);
      l >>= 1; r >>= 1;
    }
    return op(left, right);
  }
  template <class G>
  int max_right(int l, G g){
    assert(0 <= l && l <= n);
    assert(g(inf));
    if(l == n) return n;
    l += len;
    for(int i = log; i >= 1; i--) push(l >> i);
    T sm = inf;
    do {
      l /= l & -l;
      if(!g(op(sm, d[l]))){
        while(l < len){
          push(l);
          l <<= 1;
          if(g(op(sm, d[l]))){
            sm = op(sm, d[l]);
            l++;
          }
        }
        return l - len;
      }
      sm = op(sm, d[l]);
      l++;
    }while(l & (l - 1));
    return n;
  }
  template <class G>
  int min_left(int r, G g){
    assert(0 <= r && r <= n);
    assert(g(inf));
    if(r == 0) return 0;
    r += len;
    for(int i = log; i >= 1; i--) push((r - 1) >> i);
    T sm = inf;
    do {
      r /= r & -r;
      if(r > 1) r--;
      if(!g(op(d[r], sm))){
        while(r < len){
          push(r);
          r = r * 2 + 1;
          if(g(op(d[r], sm))){
            sm = op(d[r], sm);
            r--;
          }
        }
        return r + 1 - len;
      }
      sm = op(d[r], sm);
    }while(r & (r - 1));
    return 0;
  }
  private:
  vector<T> d, lazy;
  const T inf = -op(numeric_limits<T>::max(), -numeric_limits<T>::max());
  int n = 1, log = 0, len = 0;
  inline void update(const int k){ d[k] = op(d[2*k], d[2*k+1]); }
  inline void apply(const int k, const T &x){
    d[k] = x;
    if(k < len) lazy[k] = x;
  }
  inline void push(const int k){
    if(lazy[k] == inf) return;
    apply(2*k, lazy[k]);
    apply(2*k+1, lazy[k]);
    lazy[k] = inf;
  }
};
#line 6 "test/aoj/DSL/DSL_2_F.test.cpp"

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n,q;
  cin >> n >> q;
  LazySegmentTree<int,min> seg(n);
  while(q--){
    int t; cin >> t;
    if(t == 0){
      int l,r,x;
      cin >> l >> r >> x;
      seg.update(l, r+1, x);
    }else{
      int l,r;
      cin >> l >> r;
      cout << seg.query(l, r+1) << "\n";
    }
  }
}
Back to top page