結果
問題 | No.875 Range Mindex Query |
ユーザー |
|
提出日時 | 2019-09-07 19:43:13 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 400 ms / 2,000 ms |
コード長 | 2,968 bytes |
コンパイル時間 | 1,959 ms |
コンパイル使用メモリ | 151,520 KB |
最終ジャッジ日時 | 2025-01-07 17:18:30 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 18 |
ソースコード
//include//------------------------------------------#include <vector>#include <list>#include <map>#include <unordered_map>#include <climits>#include <set>#include <unordered_set>#include <deque>#include <stack>#include <bitset>#include <algorithm>#include <functional>#include <numeric>#include <utility>#include <sstream>#include <iostream>#include <iomanip>#include <cstdio>#include <cmath>#include <cstdlib>#include <cctype>#include <string>#include <cstring>#include <ctime>#include <queue>#include <random>#include <complex>#include <regex>#include <locale>#include <random>#include <type_traits>using namespace std;#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}using LL = long long;//------------------------------------------//------------------------------------------template<typename T>struct SegmentTree {private:using Func = function<T(T, T)>;int n;vector<T> node;T init_v;Func func;public:SegmentTree(vector<T> a, Func _func, T _init_v) {int sz = a.size();n = 1;init_v = _init_v;func = _func;while (n < sz) n *= 2;node.resize(2 * n, init_v);for (int i = 0; i < sz; i++) node[i + n - 1] = a[i];for (int i = n - 2; i >= 0; i--) node[i] = func(node[i * 2 + 1], node[i * 2 + 2]);}void update(int pos, T v) {int k = pos + n - 1;node[k] = v;while (k > 0) {k = (k - 1) / 2;node[k] = func(node[k * 2 + 1], node[k * 2 + 2]);}}T get(int pos) {int k = pos + n - 1;return node[k];}T query(int a, int b, int k = 0, int l = 0, int r = -1) {if (r < 0) r = n;if (r <= a || b <= l) return init_v;if (a <= l && r <= b)return node[k];T lv = query(a, b, k * 2 + 1, l, (l + r) / 2);T rv = query(a, b, k * 2 + 2, (l + r) / 2, r);return func(lv, rv);}};int main() {int N;cin >> N;int Q;cin >> Q;vector<int> a(N);for (int i = 0; i < N; i++) cin >> a[i];SegmentTree<int> tree(a, [](const int a, const int b) {return min(a, b);}, INT_MAX);map<int, int> mp;for (int i = 0; i < N; i++) mp[a[i]] = i;for (int i = 0; i < Q; i++) {int which, l, r;cin >> which >> l >> r;l--, r--;if (which == 1) {int lv = tree.get(l);int rv = tree.get(r);tree.update(r, lv);tree.update(l, rv);mp[lv] = r;mp[rv] = l;}if (which == 2) {cout << mp[tree.query(l, r + 1)] + 1 << endl;}}}