結果
| 問題 | No.875 Range Mindex Query |
| コンテスト | |
| ユーザー |
Forested
|
| 提出日時 | 2020-07-28 10:06:59 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 67 ms / 2,000 ms |
| コード長 | 2,886 bytes |
| コンパイル時間 | 922 ms |
| コンパイル使用メモリ | 99,212 KB |
| 実行使用メモリ | 6,016 KB |
| 最終ジャッジ日時 | 2024-06-28 20:33:35 |
| 合計ジャッジ時間 | 2,428 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 18 |
ソースコード
// Template
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <cmath>
#include <complex>
#define rep(i, x) for (int i = 0; i < (x); ++i)
#define rng(i, x, y) for (int i = (x); i < (y); ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003;
template <typename T> inline bool chmin(T &x, const T &y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T &x, const T &y) {if (x < y) {x = y; return 1;} return 0;}
void solve();
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(10);
solve();
return 0;
}
// Segment Tree
template <typename Operator>
struct SegmentTree {
Operator OP;
using TypeNode = decltype(OP.NodeE);
int length;
vector<TypeNode> node;
SegmentTree (int N) {
length = 1;
while (length < N) length <<= 1;
node.assign(length << 1, OP.NodeE);
}
SegmentTree (vector<TypeNode> &vec) {
length = 1;
while (length < sz(vec)) length <<= 1;
node.assign(2 * length, OP.NodeE);
rep(i, sz(vec)) node[i + length] = vec[i];
for (int i = length - 1; i > 0; --i) node[i] = OP.func(node[(i << 1) + 0], node[(i << 1) + 1]);
}
void update(int idx, TypeNode val) {
idx += length;
node[idx] = OP.change(node[idx], val);
while (idx >>= 1) node[idx] = OP.func(node[(idx << 1) + 0], node[(idx << 1) + 1]);
}
TypeNode get(int l, int r) {
l += length;
r += length;
TypeNode vl = OP.NodeE, vr = OP.NodeE;
while (r > l) {
if (l & 1) vl = OP.func(vl, node[l++]);
if (r & 1) vr = OP.func(node[--r], vr);
l >>= 1;
r >>= 1;
}
return OP.func(vl, vr);
}
};
struct hoge {
using NodeType = pair<int, int>;
NodeType NodeE = pair<int, int>(inf, -1);
NodeType func(NodeType x, NodeType y) {return min(x, y);}
NodeType change(NodeType x, NodeType y) {return y;}
};
// Main Code
void solve() {
int n, q;
cin >> n >> q;
vector<pair<int, int>> a(n);
rep(i, n) {
cin >> a[i].first;
a[i].second = i;
}
SegmentTree<hoge> ST(a);
rep(_, q) {
int num, l, r;
cin >> num >> l >> r;
--l; --r;
if (num == 1) {
auto a = ST.node[l + ST.length], b = ST.node[r + ST.length];
a.second = r; b.second = l;
ST.update(l, b); ST.update(r, a);
} else {
auto a = ST.get(l, r + 1);
cout << a.second + 1 << "\n";
}
}
return;
}
Forested