結果
問題 | No.1234 典型RMQ |
ユーザー | satashun |
提出日時 | 2020-09-18 21:27:49 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 274 ms / 2,000 ms |
コード長 | 4,634 bytes |
コンパイル時間 | 2,376 ms |
コンパイル使用メモリ | 205,588 KB |
実行使用メモリ | 8,192 KB |
最終ジャッジ日時 | 2024-11-09 01:42:29 |
合計ジャッジ時間 | 9,405 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | AC | 2 ms
5,248 KB |
testcase_06 | AC | 261 ms
7,936 KB |
testcase_07 | AC | 208 ms
5,248 KB |
testcase_08 | AC | 274 ms
8,192 KB |
testcase_09 | AC | 241 ms
5,632 KB |
testcase_10 | AC | 266 ms
7,936 KB |
testcase_11 | AC | 251 ms
7,808 KB |
testcase_12 | AC | 235 ms
5,632 KB |
testcase_13 | AC | 209 ms
5,248 KB |
testcase_14 | AC | 237 ms
5,632 KB |
testcase_15 | AC | 226 ms
5,504 KB |
testcase_16 | AC | 267 ms
7,936 KB |
testcase_17 | AC | 246 ms
5,632 KB |
testcase_18 | AC | 196 ms
5,248 KB |
testcase_19 | AC | 268 ms
8,064 KB |
testcase_20 | AC | 209 ms
8,192 KB |
testcase_21 | AC | 252 ms
7,808 KB |
testcase_22 | AC | 226 ms
8,064 KB |
testcase_23 | AC | 225 ms
8,064 KB |
testcase_24 | AC | 226 ms
8,192 KB |
testcase_25 | AC | 225 ms
8,064 KB |
testcase_26 | AC | 227 ms
8,192 KB |
testcase_27 | AC | 2 ms
5,248 KB |
testcase_28 | AC | 2 ms
5,248 KB |
testcase_29 | AC | 2 ms
5,248 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; #define pb push_back #define eb emplace_back #define mp make_pair #define fi first #define se second #define rep(i, n) rep2(i, 0, n) #define rep2(i, m, n) for (int i = m; i < (n); i++) #define per(i, b) per2(i, 0, b) #define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--) #define ALL(c) (c).begin(), (c).end() #define SZ(x) ((int)(x).size()) constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); } template <class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; } template <class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; } template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << "(" << p.first << "," << p.second << ")"; return os; } template <class T> ostream& operator<<(ostream& os, const vector<T>& v) { os << "{"; rep(i, v.size()) { if (i) os << ","; os << v[i]; } os << "}"; return os; } #ifdef LOCAL void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...); } #define debug(...) \ cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl #else #define debug(...) (void(0)) #define dump(x) (void(0)) #endif // index of root = 1 // T1 : array value type // T2 : action type template <class U> struct segtree { using T1 = typename U::T1; using T2 = typename U::T2; int sz, H; V<T1> a; V<T2> b; segtree() { sz = H = -1; } segtree(int n) { sz = 1, H = 0; while (sz < n) { sz *= 2, ++H; } a.assign(sz * 2, U::id1()); b.assign(sz * 2, U::id2()); } segtree(const V<T1>& vec) { int n = vec.size(); sz = 1, H = 0; while (sz < n) { sz *= 2, ++H; } a.assign(sz * 2, U::id1()); b.assign(sz * 2, U::id2()); for (int i = 0; i < n; ++i) { a[sz + i] = vec[i]; } for (int i = sz - 1; i >= 1; --i) { a[i] = U::op11(a[i << 1 | 0], a[i << 1 | 1]); } } void up(int i) { while (i >>= 1) { T1 xl = U::op21(b[i << 1 | 0], a[i << 1 | 0]); T1 xr = U::op21(b[i << 1 | 1], a[i << 1 | 1]); a[i] = U::op11(xl, xr); } } void propagate(int p) { for (int h = H; h > 0; --h) { int i = p >> h; a[i] = U::op21(b[i], a[i]); b[i << 1 | 0] = U::op22(b[i], b[i << 1 | 0]); b[i << 1 | 1] = U::op22(b[i], b[i << 1 | 1]); b[i] = U::id2(); } } // action on [p, q) void apply(int p, int q, T2 x) { if (p == q) return; p += sz, q += sz; propagate(p); propagate(q - 1); for (int l = p, r = q; l < r; l >>= 1, r >>= 1) { if (l & 1) b[l] = U::op22(x, b[l]), ++l; if (r & 1) --r, b[r] = U::op22(x, b[r]); } up(p); up(q - 1); } T1 get(int l, int r) { if (l == r) return U::id1(); l += sz, r += sz; propagate(l); propagate(r - 1); T1 lval = U::id1(), rval = U::id1(); for (; l < r; l >>= 1, r >>= 1) { if (l & 1) lval = U::op11(lval, U::op21(b[l], a[l])), ++l; if (r & 1) --r, rval = U::op11(U::op21(b[r], a[r]), rval); } return U::op11(lval, rval); } }; // for https://atcoder.jp/contests/tenka1-2016-qualb/tasks/tenka1_2016_qualB_d // range addition and range minimum query needed, initialization must be cared // (set all to 0, while id1 = INF) // modify only U for use constexpr ll INF = TEN(18); struct U { using T1 = ll; using T2 = ll; static T1 id1() { return INF; } static T2 id2() { return 0; } static T1 op11(const T1& a, const T1& b) { return min(a, b); } static T1 op21(const T2& b, const T1& a) { return b + a; } static T2 op22(const T2& a, const T2& b) { return a + b; } }; int main() { int N; cin >> N; V<ll> A(N); rep(i, N) cin >> A[i]; segtree<U> seg(A); int Q; cin >> Q; while (Q--) { int k, l, r, c; cin >> k >> l >> r >> c; --l; if (k == 1) { seg.apply(l, r, c); } else { auto a = seg.get(l, r); cout << a << '\n'; } } return 0; }