結果
問題 | No.875 Range Mindex Query |
ユーザー | t33f |
提出日時 | 2019-09-07 11:32:45 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 279 ms / 2,000 ms |
コード長 | 1,880 bytes |
コンパイル時間 | 803 ms |
コンパイル使用メモリ | 71,936 KB |
実行使用メモリ | 5,256 KB |
最終ジャッジ日時 | 2023-09-08 13:49:15 |
合計ジャッジ時間 | 3,897 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,380 KB |
testcase_01 | AC | 2 ms
4,384 KB |
testcase_02 | AC | 3 ms
4,380 KB |
testcase_03 | AC | 1 ms
4,384 KB |
testcase_04 | AC | 2 ms
4,376 KB |
testcase_05 | AC | 2 ms
4,376 KB |
testcase_06 | AC | 2 ms
4,380 KB |
testcase_07 | AC | 3 ms
4,380 KB |
testcase_08 | AC | 3 ms
4,380 KB |
testcase_09 | AC | 2 ms
4,376 KB |
testcase_10 | AC | 3 ms
4,376 KB |
testcase_11 | AC | 204 ms
5,180 KB |
testcase_12 | AC | 167 ms
4,380 KB |
testcase_13 | AC | 144 ms
5,256 KB |
testcase_14 | AC | 143 ms
5,156 KB |
testcase_15 | AC | 195 ms
5,096 KB |
testcase_16 | AC | 260 ms
5,140 KB |
testcase_17 | AC | 279 ms
5,088 KB |
testcase_18 | AC | 271 ms
5,056 KB |
ソースコード
#include <iostream> using namespace std; class SegTree { using T = pair<int, int>; static const T& op(const T& lhs, const T& rhs) { // binary operator return min(lhs, rhs); } const int N; T *data; static int calc_size(int sz) { int n = 1; while (sz > n) n *= 2; return n; } public: explicit SegTree(int sz) : N(calc_size(sz)) { data = new T[2*N-1]; } ~SegTree() { delete[] data; } T query(int a, int b, int i = -1, int l = -1, int r = -1) const { if (i == -1) { i = 0; l = 0; r = N; } if (a <= l && r <= b) return data[i]; int m = (l+r)/2; if (b <= m) return query(a, b, 2*i+1, l, m); if (m <= a) return query(a, b, 2*i+2, m, r); T v1 = query(a, b, 2*i+1, l, m), v2 = query(a, b, 2*i+2, m, r); return op(v1, v2); } T get(int i) const { return data[i + N - 1]; } void update(int i, int v) { int x = i + N - 1; data[x] = {v, i}; while (x > 0) { x = (x-1)/2; data[x] = op(data[2*x+1], data[2*x+2]); } } void dump() { for (int i = 0; i < 2*N-1; i++) cerr << i << ' ' << data[i].first << ' ' << data[i].second << endl; } }; int main() { int n, q; cin >> n >> q; SegTree st(n); for (int i = 0; i < n; i++) { int a; cin >> a; st.update(i, a); } while (q--) { // st.dump(); // for (int i = 0; i < n; i++) cerr << st.get(i).first << ' ' << st.get(i).second << ' '; cerr << endl; int x, l, r; cin >> x >> l >> r; l--; r--; if (x == 1) { int al = st.get(l).first, ar = st.get(r).first; st.update(l, ar); st.update(r, al); } else { cout << st.query(l, r+1).second + 1 << endl; } } }