Submit Info #3605

Problem Lang User Status Time Memory
Static RMQ cpp mdstoy AC 341 ms 9.23 MiB

ケース詳細
Name Status Time Memory
example_00 AC 7 ms 0.56 MiB
max_random_00 AC 335 ms 9.18 MiB
max_random_01 AC 333 ms 9.23 MiB
max_random_02 AC 336 ms 8.88 MiB
max_random_03 AC 341 ms 9.23 MiB
max_random_04 AC 336 ms 9.08 MiB
random_00 AC 275 ms 8.24 MiB
random_01 AC 281 ms 8.61 MiB
random_02 AC 187 ms 3.62 MiB
random_03 AC 62 ms 7.95 MiB
random_04 AC 89 ms 6.79 MiB
small_00 AC 7 ms 0.58 MiB
small_01 AC 5 ms 0.61 MiB
small_02 AC 6 ms 0.68 MiB
small_03 AC 5 ms 0.68 MiB
small_04 AC 6 ms 0.69 MiB
small_05 AC 4 ms 0.62 MiB
small_06 AC 7 ms 0.68 MiB
small_07 AC 5 ms 0.62 MiB
small_08 AC 5 ms 0.69 MiB
small_09 AC 7 ms 0.60 MiB

#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define FOR(i, m, n) for (int i = (m); i < (n); i++) #define FORR(i, m, n) for (int i = (m); i >= (n); i--) #define REP(i, n) FOR(i, 0, (n)) #define REPR(i, n) FORR(i, (n) - 1, 0) #define REP1(i, n) FOR(i, 1, (n) + 1) #define REPS(c, s) for (char c : s) #define ALL(c) (c).begin(), (c).end() #define SORT(c) sort(ALL(c)) #define REV(c) reverse(ALL(c)) #define sz(v) (int)v.size() #define endl '\n' template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;} template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;} const int MOD = 1000000007; const int INF = 1000000001; const ll LINF = 1000000001000000001LL; void solve(); int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(numeric_limits<double>::max_digits10); solve(); return 0; } class SegmentTree { int n; vector<int> node; public: SegmentTree(vector<int> v) { n = 1; int s = v.size(); while (n < s) n *= 2; node.resize(2 * n - 1, INF); for (int i = 0; i < s; i++) node[i + n - 1] = v[i]; for (int i = n - 2; i >= 0; i--) node[i] = min(node[2 * i + 1], node[2 * i + 2]); } void update(int x, int val) { x += (n - 1); node[x] = val; while(x > 0) { x = (x - 1) / 2; node[x] = min(node[2 * x + 1], node[2 * x + 2]); } } int find(int a, int b, int k = 0, int l = 0, int r = -1) { if(r < 0) r = n; if(r <= a || b <= l) return INF; if(a <= l && r <= b) return node[k]; int vl = find(a, b, 2 * k + 1, l, (l + r) / 2); int vr = find(a, b, 2 * k + 2, (l + r) / 2, r); return min(vl, vr); } }; void solve() { int n, q; cin >> n >> q; vector<int> a(n); REP(i, n) cin >> a[i]; SegmentTree st(a); REP(i, q) { int l, r; cin >> l >> r; cout << st.find(l, r) << endl; } }