結果

問題 No.1234 典型RMQ
ユーザー CleyLCleyL
提出日時 2023-12-18 19:54:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 386 ms / 2,000 ms
コード長 4,858 bytes
コンパイル時間 1,478 ms
コンパイル使用メモリ 138,368 KB
実行使用メモリ 9,848 KB
最終ジャッジ日時 2023-12-18 19:54:57
合計ジャッジ時間 11,853 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 1 ms
6,676 KB
testcase_06 AC 347 ms
9,152 KB
testcase_07 AC 284 ms
6,676 KB
testcase_08 AC 386 ms
9,728 KB
testcase_09 AC 324 ms
6,676 KB
testcase_10 AC 353 ms
9,464 KB
testcase_11 AC 358 ms
9,044 KB
testcase_12 AC 318 ms
6,676 KB
testcase_13 AC 286 ms
6,676 KB
testcase_14 AC 324 ms
6,676 KB
testcase_15 AC 316 ms
6,676 KB
testcase_16 AC 360 ms
9,416 KB
testcase_17 AC 321 ms
6,676 KB
testcase_18 AC 265 ms
6,676 KB
testcase_19 AC 376 ms
9,668 KB
testcase_20 AC 250 ms
9,848 KB
testcase_21 AC 352 ms
9,116 KB
testcase_22 AC 294 ms
9,848 KB
testcase_23 AC 291 ms
9,848 KB
testcase_24 AC 289 ms
9,848 KB
testcase_25 AC 290 ms
9,848 KB
testcase_26 AC 289 ms
9,848 KB
testcase_27 AC 1 ms
6,676 KB
testcase_28 AC 2 ms
6,676 KB
testcase_29 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 2 "/home/sakflat/CP/_library/cpp/template/template.cpp"

//yukicoder@cpp17

#include <iostream>
#include <iomanip>

#include <algorithm>

#include <cmath>
#include <cctype>
#include <climits>
#include <cassert>

#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>

#include <random>

#include <bitset>

#include <complex>

#include <utility>

#include <numeric>

#include <functional>


using namespace std;
using ll = long long;
using P = pair<ll,ll>;

const ll MOD = 998244353;
const ll MODx = 1000000007;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62LL)-1;
const double EPS = (1e-10);

P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};




template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }
 
 /*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる

計算量は変わらないが楽できるシリーズ
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる
*/

/*
function corner below
*/


/*
Function corner above
*/

/* comment outed because can cause bugs
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}
*/
#line 2 "/home/sakflat/CP/_library/cpp/template/basic.cpp"

#line 1 "/home/sakflat/CP/_library/cpp/data-structure/segment-tree/lazy-add-segment-tree.cpp"
template< typename T, typename F>
struct LazySegmentTree{
  private:
    int n;
    vector<T> node,lazy;
    vector<bool> lazyTrigger;

    F f;
    T initer;

  public:
    LazySegmentTree(int n_, F f, T initer) : f(f),initer(initer) {
      n = 1;
      while(n < n_)n*=2;
      node.resize(2*n-1, initer);
      lazy.resize(2*n-1, 0);
      lazyTrigger.resize(2*n-1, false);
    }

    LazySegmentTree(int n_, F f, T initer, vector<T> base) : f(f),initer(initer) {
      n = 1;
      while(n < n_)n*=2;
      node.resize(2*n-1, initer);
      set(base);
      lazy.resize(2*n-1, 0);
      lazyTrigger.resize(2*n-1, false);
    }

    void set(vector<T> base){
      int x = 1;
      while(x < n)x *= 2;
      x--;
      for(int i = 0; base.size() > i; i++){
        node[i+x] = base[i];
      }
      for(int i = x-1; 0 <= i; i--){
        node[i] = f(node[i*2+1], node[i*2+2]);
      }
    }

    void eval(int k, int l, int r){
      if(lazyTrigger[k]){
        node[k] += lazy[k]/(r-l+1);
        if(r-l >= 1){
          lazy[k*2+1] += lazy[k]/2;
          lazyTrigger[k*2+1] = true;
          lazy[k*2+2] += lazy[k]/2;
          lazyTrigger[k*2+2] = true;

        }
        lazy[k] = 0;
        lazyTrigger[k] = false;
      }
    }

    //TODO: update -> apply(such as update and add)
    void add(int a,int b, T x, int k = 0, int l = 0, int r = -1){
      if(r < 0) r = n-1;
      eval(k, l, r);
      if(b < l || r < a){
        return;
      }
      if(a <= l && r <= b){
        lazy[k] = x*((r-l+1));
        lazyTrigger[k] = true;
        eval(k, l, r);
      }else{
        add(a,b,x,2*k+1, l, (l+r)/2);
        add(a,b,x,2*k+2,(l+r)/2+1,r);

        node[k] = f(node[k*2+1],node[k*2+2]);
      }
    }

    T getf(int a,int b, int k=0, int l=0, int r=-1){
      if(r < 0){
        r = n-1;
      }
      if(r < a || b < l){
        return (1LL<<61);
      }
      eval(k,l,r);
      if(a <= l && r <= b){
        return node[k];
      }
      T vl = getf(a,b,2*k+1,l,(l+r)/2);
      T vr = getf(a,b,2*k+2,(l+r)/2+1,r);
      return f(vl,vr);
    }

    void debug(){
      int nw = 1;
      int curr = 1;
      cout << "---begin---" << endl;
      for(int i = 0; 2*n-1 > i; i++){
        cout << "(" << node[i] << ", " << lazy[i] << " (" << lazyTrigger[i] << ")) ";
        if(nw == curr)cout << endl,nw *= 2, curr=1;
        else curr++;
      }
      cout << "---end---" << endl;
    }
};


template <typename T, typename F>
LazySegmentTree<T, F> get_lazy_segment_tree(int N, const F &f, T initer){
  return LazySegmentTree{N,f,initer};
}

template <typename T, typename F>
LazySegmentTree<T, F> get_lazy_segment_tree(int N, const F &f, T initer, vector<T> base){
  return LazySegmentTree(N, f, initer, base);
}

int main(){
  int n;cin>>n;
  vector<long long> A(n);
  for(int i = 0; n > i; i++)cin>>A[i];
  auto ST = get_lazy_segment_tree(n, [](long long a, long long b){return min(a,b);}, 0LL, A);
  int q;cin>>q;
  for(int i = 0; q > i; i++){
    int k;cin>>k;
    if(k == 1){
      int l,r;long long c;cin>>l>>r>>c;l--;r--;
      ST.add(l,r,c);
    }else{
      int l,r,c;cin>>l>>r>>c;l--;r--;
      cout << ST.getf(l, r) << endl;
    }
  }
  return 0;
}
0