結果

問題 No.1234 典型RMQ
ユーザー ShibuyapShibuyap
提出日時 2020-09-18 21:48:02
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 210 ms / 2,000 ms
コード長 2,103 bytes
コンパイル時間 1,866 ms
コンパイル使用メモリ 198,880 KB
実行使用メモリ 6,656 KB
最終ジャッジ日時 2023-08-08 18:37:30
合計ジャッジ時間 7,818 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,388 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 190 ms
5,680 KB
testcase_07 AC 158 ms
4,380 KB
testcase_08 AC 210 ms
6,504 KB
testcase_09 AC 175 ms
4,972 KB
testcase_10 AC 197 ms
6,204 KB
testcase_11 AC 190 ms
5,524 KB
testcase_12 AC 179 ms
4,816 KB
testcase_13 AC 156 ms
4,380 KB
testcase_14 AC 184 ms
4,860 KB
testcase_15 AC 170 ms
4,540 KB
testcase_16 AC 199 ms
5,984 KB
testcase_17 AC 176 ms
4,848 KB
testcase_18 AC 151 ms
4,380 KB
testcase_19 AC 203 ms
6,464 KB
testcase_20 AC 154 ms
6,576 KB
testcase_21 AC 193 ms
5,764 KB
testcase_22 AC 185 ms
6,612 KB
testcase_23 AC 185 ms
6,656 KB
testcase_24 AC 182 ms
6,612 KB
testcase_25 AC 182 ms
6,596 KB
testcase_26 AC 186 ms
6,540 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

long long int INF = 1e18;
int const TREE_SIZE = 1 << 21;
long long int seg_tree[TREE_SIZE] = {};
long long int c_diff[TREE_SIZE] = {}; // 子との差

// [a, b) の最小値を求める
// find_(a, b, 1, 0, 0, TREE_SIZE / 2)
long long int find_(int a, int b, int index, long long int diff, int l, int r){
	seg_tree[index] += diff;
	c_diff[index] += diff;
	
	if(r <= a || b <= l){
		return INF;
	}
	if(a <= l && r <= b){
		return seg_tree[index];
	}
	
	long long int ret = INF;
	ret = min(ret, find_(a, b, index * 2, c_diff[index], l, (l + r) / 2));
	ret = min(ret, find_(a, b, index * 2 + 1, c_diff[index], (l + r) / 2, r));
	c_diff[index] = 0;
	return ret;
}

// [a, b) に num を足す
// add(a, b, 1, num, 0, 0, TREE_SIZE / 2);
long long int add(int a, int b, int index, long long int num, long long int diff, int l, int r){
	seg_tree[index] += diff;
	c_diff[index] += diff;
	
	if(r <= a || b <= l){
		return seg_tree[index];
	}
	if(a <= l && r <= b){
		seg_tree[index] += num;
		c_diff[index] += num;
		return seg_tree[index];
	}
	
	long long int ret = INF;
	ret = min(ret, add(a, b, index * 2, num, c_diff[index], l, (l + r) / 2));
	ret = min(ret, add(a, b, index * 2 + 1, num, c_diff[index], (l + r) / 2, r));
	c_diff[index] = 0;
	return seg_tree[index] = ret;
}

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(0);
    
	int n, q;
	cin >> n;

    rep(i,n){
        ll a;
        cin >> a;
        add(i,i+1,1,a,0,0,TREE_SIZE/2);
    }
    
    cin >> q;
	for(int loop = 0; loop < q; loop++){
		long long int num, s, t, x;
		cin >> num;
		if(num == 1){
			cin >> s >> t >> x;
            s--; t--;
			add(s, t + 1, 1, x, 0, 0, TREE_SIZE / 2);
		}else{
			cin >> s >> t >> x;
            s--; t--;
			cout << find_(s, t + 1, 1, 0, 0, TREE_SIZE / 2) << endl;
		}
	}
	
	return 0;
}

0