結果

問題 No.1234 典型RMQ
ユーザー SSRSSSRS
提出日時 2020-09-18 21:29:46
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 270 ms / 2,000 ms
コード長 1,897 bytes
コンパイル時間 2,182 ms
コンパイル使用メモリ 203,832 KB
実行使用メモリ 8,088 KB
最終ジャッジ日時 2023-08-08 18:32:41
合計ジャッジ時間 9,458 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 266 ms
7,824 KB
testcase_07 AC 210 ms
4,380 KB
testcase_08 AC 264 ms
7,756 KB
testcase_09 AC 244 ms
5,300 KB
testcase_10 AC 267 ms
7,796 KB
testcase_11 AC 246 ms
7,480 KB
testcase_12 AC 235 ms
5,612 KB
testcase_13 AC 221 ms
4,380 KB
testcase_14 AC 243 ms
5,384 KB
testcase_15 AC 236 ms
5,384 KB
testcase_16 AC 268 ms
7,988 KB
testcase_17 AC 240 ms
5,296 KB
testcase_18 AC 202 ms
4,380 KB
testcase_19 AC 270 ms
7,720 KB
testcase_20 AC 207 ms
7,772 KB
testcase_21 AC 260 ms
7,812 KB
testcase_22 AC 227 ms
7,672 KB
testcase_23 AC 232 ms
8,088 KB
testcase_24 AC 230 ms
7,764 KB
testcase_25 AC 225 ms
7,744 KB
testcase_26 AC 224 ms
7,752 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>
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