結果
問題 | No.875 Range Mindex Query |
ユーザー | Dente |
提出日時 | 2019-12-03 02:35:08 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 303 ms / 2,000 ms |
コード長 | 2,113 bytes |
コンパイル時間 | 1,917 ms |
コンパイル使用メモリ | 177,308 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-05-04 00:33:09 |
合計ジャッジ時間 | 5,732 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 3 ms
6,816 KB |
testcase_02 | AC | 4 ms
6,812 KB |
testcase_03 | AC | 2 ms
6,812 KB |
testcase_04 | AC | 3 ms
6,940 KB |
testcase_05 | AC | 3 ms
6,940 KB |
testcase_06 | AC | 3 ms
6,940 KB |
testcase_07 | AC | 3 ms
6,940 KB |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | AC | 2 ms
6,940 KB |
testcase_10 | AC | 4 ms
6,940 KB |
testcase_11 | AC | 250 ms
6,940 KB |
testcase_12 | AC | 206 ms
6,944 KB |
testcase_13 | AC | 170 ms
6,940 KB |
testcase_14 | AC | 168 ms
6,940 KB |
testcase_15 | AC | 235 ms
6,940 KB |
testcase_16 | AC | 281 ms
6,940 KB |
testcase_17 | AC | 303 ms
6,940 KB |
testcase_18 | AC | 299 ms
6,940 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #define REP(i,a) for(int i = 0; i < (a); i++) #define ALL(a) (a).begin(),(a).end() typedef long long ll; typedef pair<int, int> P; const int INF = 1e9; const long long LINF = 1e18; const long long MOD = 1e9 + 7; /* SegmentTree<int> seg(f, def) のように宣言する RMQ の場合 : auto f = [](int a, int b){return min(a, b);}; int def = INF; */ template <typename Monoid> struct SegmentTree{ using F = function<Monoid(Monoid, Monoid)>; int n; vector<Monoid> dat; F f; Monoid def; SegmentTree(F f, Monoid def) : f(f), def(def) {} void build(const vector<Monoid> & vec){ int siz = vec.size(); n = 1; while(n < siz) n *= 2; dat.assign(2 * n - 1, def); for(int i = 0; i < siz; i++) dat[n - 1 + i] = vec[i]; for(int i = n - 2; i >= 0; i--) dat[i] = f(dat[2 * i + 1], dat[2 * i + 2]); } void update(int k, Monoid x){ k += (n - 1); dat[k] = x; while(k > 0){ k = (k - 1) / 2; dat[k] = f(dat[2 * k + 1], dat[2 * k + 2]); } } Monoid query(int a, int b){ return query(a, b, 0, 0, n); } private: Monoid query(int a, int b, int k, int l, int r){ if(r <= a || b <= l) return def; if(a <= l && r <= b) return dat[k]; Monoid vl = query(a, b, 2 * k + 1, l, (l + r) / 2); Monoid vr = query(a, b, 2 * k + 2, (l + r) / 2, r); return f(vl, vr); } }; signed main(){ int n,q; cin >> n >> q; vector<P> a(n); REP(i,n){ cin >> a[i].first; a[i].second = i + 1; } auto f = [](P a, P b){return min(a, b);}; SegmentTree<P> seg(f, P(INF, -1)); seg.build(a); int Q,l,r; REP(i,q){ cin >> Q >> l >> r; l--; r--; if(Q == 1){ int t = seg.query(l, l + 1).first; seg.update(l, P(seg.query(r, r + 1).first, l + 1)); seg.update(r, P(t, r + 1)); }else{ cout << seg.query(l, r + 1).second << endl; } } return 0; }