結果
問題 | No.1234 典型RMQ |
ユーザー | stoq |
提出日時 | 2020-09-23 03:54:52 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 166 ms / 2,000 ms |
コード長 | 5,041 bytes |
コンパイル時間 | 3,083 ms |
コンパイル使用メモリ | 220,728 KB |
実行使用メモリ | 8,960 KB |
最終ジャッジ日時 | 2024-11-09 02:23:37 |
合計ジャッジ時間 | 7,571 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 3 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 | 158 ms
8,320 KB |
testcase_07 | AC | 115 ms
5,248 KB |
testcase_08 | AC | 162 ms
8,704 KB |
testcase_09 | AC | 141 ms
6,016 KB |
testcase_10 | AC | 162 ms
8,704 KB |
testcase_11 | AC | 154 ms
8,192 KB |
testcase_12 | AC | 138 ms
5,760 KB |
testcase_13 | AC | 118 ms
5,248 KB |
testcase_14 | AC | 138 ms
6,016 KB |
testcase_15 | AC | 131 ms
5,760 KB |
testcase_16 | AC | 166 ms
8,576 KB |
testcase_17 | AC | 139 ms
5,888 KB |
testcase_18 | AC | 105 ms
5,248 KB |
testcase_19 | AC | 164 ms
8,832 KB |
testcase_20 | AC | 87 ms
8,960 KB |
testcase_21 | AC | 155 ms
8,320 KB |
testcase_22 | AC | 114 ms
8,960 KB |
testcase_23 | AC | 114 ms
8,832 KB |
testcase_24 | AC | 114 ms
8,960 KB |
testcase_25 | AC | 114 ms
8,832 KB |
testcase_26 | AC | 114 ms
8,832 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 |
ソースコード
#define MOD_TYPE 1 #pragma region Macros #include <bits/stdc++.h> using namespace std; #if 0 #include <boost/multiprecision/cpp_int.hpp> #include <boost/multiprecision/cpp_dec_float.hpp> using Int = boost::multiprecision::cpp_int; using lld = boost::multiprecision::cpp_dec_float_100; #endif #if 1 #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #endif using ll = long long int; using ld = long double; using ull = unsigned long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using pld = pair<ld, ld>; template <typename Q_type> using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>; constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353); //constexpr ll MOD = 1; constexpr int INF = (int)1e9 + 10; constexpr ll LINF = (ll)4e18; constexpr double PI = acos(-1.0); constexpr double EPS = 1e-9; constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0}; constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0}; #define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i) #define rep(i, n) REP(i, 0, n) #define REPI(i, m, n) for (int i = m; i < (int)(n); ++i) #define repi(i, n) REPI(i, 0, n) #define MP make_pair #define MT make_tuple #define YES(n) cout << ((n) ? "YES" : "NO") << "\n" #define Yes(n) cout << ((n) ? "Yes" : "No") << "\n" #define possible(n) cout << ((n) ? "possible" : "impossible") << "\n" #define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n" #define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n" #define all(v) v.begin(), v.end() #define NP(v) next_permutation(all(v)) #define dbg(x) cerr << #x << ":" << x << "\n"; struct io_init { io_init() { cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(30) << setiosflags(ios::fixed); }; } io_init; template <typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } inline ll CEIL(ll a, ll b) { return (a + b - 1) / b; } template <typename A, size_t N, typename T> inline void Fill(A (&array)[N], const T &val) { fill((T *)array, (T *)(array + N), val); } template <typename T, typename U> constexpr istream &operator>>(istream &is, pair<T, U> &p) noexcept { is >> p.first >> p.second; return is; } template <typename T, typename U> constexpr ostream &operator<<(ostream &os, pair<T, U> &p) noexcept { os << p.first << " " << p.second; return os; } #pragma endregion template <typename T, typename E> struct SegmentTree { using F = function<T(T, T)>; using G = function<T(T, E)>; using H = function<E(E, E)>; using P = function<E(E, int)>; int n; F f; G g; H h; P p; T ti; E ei; vector<T> dat; vector<E> laz; SegmentTree() {} SegmentTree( int n_, F f, G g, H h, T ti, E ei, P p = [](E a, int b) { return a; }) : f(f), g(g), h(h), ti(ti), ei(ei), p(p) { init(n_); } SegmentTree( vector<T> &v, F f, G g, H h, T ti, E ei, P p = [](E a, int b) { return a; }) : f(f), g(g), h(h), ti(ti), ei(ei), p(p) { init(v.size()); build(v); } void init(int n_) { n = 1; while (n < n_) n *= 2; dat.clear(); dat.resize(2 * n - 1, ti); laz.clear(); laz.resize(2 * n - 1, ei); } void build(const vector<T> v) { for (int i = 0; i < v.size(); i++) dat[i + n - 1] = v[i]; for (int i = n - 2; i >= 0; i--) dat[i] = f(dat[i * 2 + 1], dat[i * 2 + 2]); } void eval(int len, int k) { if (laz[k] == ei) return; if (k * 2 + 1 < n * 2 - 1) { laz[k * 2 + 1] = h(laz[k * 2 + 1], laz[k]); laz[k * 2 + 2] = h(laz[k * 2 + 2], laz[k]); } dat[k] = g(dat[k], p(laz[k], len)); laz[k] = ei; } T update(int a, int b, E x, int k, int l, int r) { eval(r - l, k); if (r <= a || b <= l) return dat[k]; if (a <= l && r <= b) { laz[k] = h(laz[k], x); return g(dat[k], p(laz[k], r - l)); } return dat[k] = f(update(a, b, x, k * 2 + 1, l, (l + r) / 2), update(a, b, x, k * 2 + 2, (l + r) / 2, r)); } T update(int a, int b, E x) { return update(a, b, x, 0, 0, n); } T query(int a, int b, int k, int l, int r) { eval(r - l, k); if (r <= a || b <= l) return ti; if (a <= l && r <= b) return dat[k]; T vl = query(a, b, k * 2 + 1, l, (l + r) / 2); T vr = query(a, b, k * 2 + 2, (l + r) / 2, r); return f(vl, vr); } T query(int a, int b) { return query(a, b, 0, 0, n); } }; void solve() { int n; cin >> n; vector<ll> a(n); rep(i, n) cin >> a[i]; auto my_min = [](ll a, ll b) { return min(a, b); }; SegmentTree<ll, ll> sg(a, my_min, plus<ll>(), plus<ll>(), 4e18, 0); int q; cin >> q; rep(qi, q) { int k, l, r; ll c; cin >> k >> l >> r >> c; l--; if (k == 1) { sg.update(l, r, c); } else { cout << sg.query(l, r) << "\n"; } } } int main() { solve(); }