結果
問題 | No.875 Range Mindex Query |
ユーザー | OKCH3COOH |
提出日時 | 2019-10-27 14:15:34 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 207 ms / 2,000 ms |
コード長 | 3,525 bytes |
コンパイル時間 | 1,199 ms |
コンパイル使用メモリ | 120,212 KB |
実行使用メモリ | 8,048 KB |
最終ジャッジ日時 | 2024-09-14 21:02:03 |
合計ジャッジ時間 | 3,430 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 3 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 3 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 3 ms
5,376 KB |
testcase_10 | AC | 3 ms
5,376 KB |
testcase_11 | AC | 131 ms
7,072 KB |
testcase_12 | AC | 103 ms
5,632 KB |
testcase_13 | AC | 88 ms
7,168 KB |
testcase_14 | AC | 87 ms
7,040 KB |
testcase_15 | AC | 118 ms
7,296 KB |
testcase_16 | AC | 189 ms
7,860 KB |
testcase_17 | AC | 207 ms
7,784 KB |
testcase_18 | AC | 201 ms
8,048 KB |
ソースコード
#include <map>#include <set>#include <vector>#include <algorithm>#include <iostream>#include <bitset>#include <cassert>#include <queue>#include <random>#include <stack>#include <iomanip>using namespace std;template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }using Int = unsigned int;using llong = long long;using Llong = unsigned long long;using ldouble = long double;using intV = vector<int>;using llongV = vector<long long>;using llongVV = vector<vector<long long>>;using Graph = vector<vector<long long>>;using costGraph = vector<vector<pair<long long, long long>>>;struct Edge {long long from;long long to;long long cost;};template<typename T>using asc = less<T>();template<typename T>using desc = greater<T>();const llong MOD = 1e9 + 7;const llong INF = 1e17;#define FOR(i, n) for (llong i = 0; i < n; i++)#define FORS(i, a, b) for (llong i = a; i < b; i++)#define FORR(i, n) for (llong i = n; i > 0; i++)#define sup(vec, a) upper_bound(vec.begin(), vec.end(), a) - vec.begin()#define inf(vec, a) lower_bound(vec.begin(), vec.end(), a) - vec.begin()class SegmentTree {public :llongV __data;llong __size;SegmentTree (llong size) {this->init(size);};void init (llong size) {// 完全二分木にするllong binSize = 0;while((1 << binSize) < size) {binSize++;}this->__size = (1 << binSize);this->__data.resize(this->__size * 2);for(llong i = 0; i < this->__size * 2; i++) {this->__data[i] = INF;}};/* メソッド */void update(llong index, llong value) {index += this->__size - 1;this->__data[index] = value;while(index > 0) {index = (index - 1) / 2;this->__data[index] = min(this->__data[index * 2 + 1], this->__data[index * 2 + 2]);}};llong __query(llong qLeft, llong qRight, llong node, llong left, llong right) {if(right <= qLeft || qRight <= left) return INF;if(qLeft <= left && right <= qRight) return this->__data[node];llong leftVal = this->__query(qLeft, qRight, node * 2 + 1, left, (left + right) / 2);llong rightVal = this->__query(qLeft, qRight, node * 2 + 2, (left + right) / 2, right);return min(leftVal, rightVal);}// wrapperllong query(llong left, llong right) {return this->__query(left, right, 0, 0, this->__size);};};int main(void) {cin.tie(0);ios::sync_with_stdio(false);llong N, Q;cin >> N >> Q;SegmentTree tree(N);llongV A(N);llongV aToI(N + 1, -1);FOR(i, N) {cin >> A[i];aToI[A[i]] = i;tree.update(i, A[i]);}llongV ans;FOR(i, Q) {llong q, l, r;cin >> q >> l >> r;l--;r--;if(q == 1) {tree.update(l, A[r]);tree.update(r, A[l]);aToI[A[r]] = l;aToI[A[l]] = r;swap(A[l], A[r]);} else {ans.push_back(aToI[tree.query(l, r + 1)]);}}for(llong a : ans) {cout << (a + 1) << endl;}return 0;}