結果
| 問題 |
No.1234 典型RMQ
|
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2023-12-18 19:54:44 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 413 ms / 2,000 ms |
| コード長 | 4,858 bytes |
| コンパイル時間 | 1,550 ms |
| コンパイル使用メモリ | 135,192 KB |
| 最終ジャッジ日時 | 2025-02-18 12:06:13 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
#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;
}