結果
問題 | No.875 Range Mindex Query |
ユーザー |
![]() |
提出日時 | 2019-09-06 21:29:08 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 285 ms / 2,000 ms |
コード長 | 1,187 bytes |
コンパイル時間 | 522 ms |
コンパイル使用メモリ | 63,752 KB |
実行使用メモリ | 5,888 KB |
最終ジャッジ日時 | 2024-06-24 16:48:52 |
合計ジャッジ時間 | 3,347 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 18 |
ソースコード
#include <iostream> #include <algorithm> #include <vector> #define rep(i, n) for(i = 0; i < (n); i++) using namespace std; typedef pair<int, int> P; const int INF = 1145141919; const int DEPTH = 17; struct SegTree { P d[1 << (DEPTH + 1)]; //(val, pos) SegTree() { int i; rep(i, 1 << (DEPTH + 1)) d[i] = P(0, 0); } void update(int pos, int x) { pos += (1 << DEPTH) - 1; d[pos] = P(x, pos - (1 << DEPTH) + 1); while (pos > 0) { pos = (pos - 1) / 2; d[pos] = min(d[pos * 2 + 1], d[pos * 2 + 2]); } } P query(int l, int r, int a = 0, int b = (1 << DEPTH), int id = 0) { if (a >= r || b <= l) return P(INF, -1); if (l <= a && b <= r) return d[id]; P u = query(l, r, a, (a + b) / 2, id * 2 + 1); P v = query(l, r, (a + b) / 2, b, id * 2 + 2); return min(u, v); } }; int n, q; int a[100000]; int type, l, r; SegTree seg; signed main() { int i; cin >> n >> q; rep(i, n) cin >> a[i]; rep(i, n) seg.update(i, a[i]); rep(i, q) { cin >> type >> l >> r; l--; r--; if (type == 1) { seg.update(l, a[r]); seg.update(r, a[l]); swap(a[l], a[r]); } else { P res = seg.query(l, r + 1); cout << res.second + 1 << endl; } } return 0; }