結果

問題 No.1234 典型RMQ
ユーザー SSRSSSRS
提出日時 2020-09-18 21:29:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 298 ms / 2,000 ms
コード長 1,897 bytes
コンパイル時間 2,242 ms
コンパイル使用メモリ 200,848 KB
実行使用メモリ 8,320 KB
最終ジャッジ日時 2024-04-26 11:00:52
合計ジャッジ時間 9,567 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 271 ms
7,808 KB
testcase_07 AC 232 ms
5,376 KB
testcase_08 AC 298 ms
8,064 KB
testcase_09 AC 255 ms
5,632 KB
testcase_10 AC 282 ms
7,936 KB
testcase_11 AC 273 ms
7,936 KB
testcase_12 AC 254 ms
5,632 KB
testcase_13 AC 230 ms
5,376 KB
testcase_14 AC 253 ms
5,760 KB
testcase_15 AC 237 ms
5,504 KB
testcase_16 AC 277 ms
7,936 KB
testcase_17 AC 257 ms
5,632 KB
testcase_18 AC 216 ms
5,376 KB
testcase_19 AC 290 ms
8,064 KB
testcase_20 AC 221 ms
8,064 KB
testcase_21 AC 271 ms
7,936 KB
testcase_22 AC 248 ms
8,064 KB
testcase_23 AC 250 ms
8,064 KB
testcase_24 AC 243 ms
8,320 KB
testcase_25 AC 236 ms
8,320 KB
testcase_26 AC 246 ms
8,064 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long INF = 10000000000000000;
template <typename T>
struct range_add_range_min{
	int N;
	vector<T> ST;
	vector<T> lazy;
	range_add_range_min(int n){
		N = 1;
		while (N < n){
			N *= 2;
		}
		ST = vector<T>(N * 2 - 1, 0);
		lazy = vector<T>(N * 2 - 1, 0);
	}
	range_add_range_min(vector<T> &A){
		int n = A.size();
		N = 1;
		while (N < n){
			N *= 2;
		}
		ST = vector<T>(N * 2 - 1, 0);
		lazy = vector<T>(N * 2 - 1, 0);
		for (int i = 0; i < n; i++){
			ST[N - 1 + i] = A[i];
		}
		for (int i = N - 2; i >= 0; i--){
			ST[i] = min(ST[i * 2 + 1], ST[i * 2 + 2]);
		}
	}
	void eval(int i){
		if (i < N - 1){
			lazy[i * 2 + 1] += lazy[i];
			lazy[i * 2 + 2] += lazy[i];
		}
		ST[i] += lazy[i];
		lazy[i] = 0;
	}
	void range_add(int L, int R, T x, int i, int l, int r){
		eval(i);
		if (R <= l || r <= L){
			return;
		} else if (L <= l && r <= R){
			lazy[i] += x;
			eval(i);
		} else {
			int m = (l + r) / 2;
			range_add(L, R, x, i * 2 + 1, l, m);
			range_add(L, R, x, i * 2 + 2, m, r);
			ST[i] = min(ST[i * 2 + 1], ST[i * 2 + 2]);
		}
	}
	void range_add(int L, int R, T x){
		range_add(L, R, x, 0, 0, N);
	}
	T range_min(int L, int R, int i, int l, int r){
		eval(i);
		if (R <= l || r <= L){
			return INF;
		} else if (L <= l && r <= R){
			return ST[i];
		} else {
			int m = (l + r) / 2;
			return min(range_min(L, R, i * 2 + 1, l, m), range_min(L, R, i * 2 + 2, m, r));
		}
	}
	T range_min(int L, int R){
		return range_min(L, R, 0, 0, N);
	}
};
int main(){
  int N;
  cin >> N;
  vector<long long> a(N);
  for (int i = 0; i < N; i++){
    cin >> a[i];
  }
  range_add_range_min<long long> ST(a);
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++){
    int k, l, r, c;
    cin >> k >> l >> r >> c;
    if (k == 1){
      ST.range_add(l - 1, r, c);
    }
    if (k == 2){
      cout << ST.range_min(l - 1, r) << endl;
    }
  }
}
0