結果
| 問題 | No.875 Range Mindex Query |
| コンテスト | |
| ユーザー |
lorent_kyopro
|
| 提出日時 | 2020-05-22 21:59:31 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 207 ms / 2,000 ms |
| コード長 | 2,755 bytes |
| 記録 | |
| コンパイル時間 | 1,946 ms |
| コンパイル使用メモリ | 200,784 KB |
| 最終ジャッジ日時 | 2025-01-10 14:43:33 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 18 |
ソースコード
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}
template <typename T>
struct SegmentTree {
using F = function<T(T, T)>;
int n;
vector<T> data;
T identity;
F operation;
F update;
SegmentTree(T _identity, F _operation, F _update)
: identity(_identity), operation(_operation), update(_update) {}
void init(int _n) {
n = 1;
while (n < _n) n <<= 1;
data.assign(n<<1, identity);
}
void build(const vector<T> &v) {
int _n = (int)v.size();
init(_n);
for (int i = 0; i < _n; ++i) data[n+i] = v[i];
for (int i = n-1; i >= 0; --i) {
data[i] = operation(data[i<<1|0], data[i<<1|1]);
}
}
void set(int i, T x) {
i += n;
data[i] = update(data[i], x);
while (i > 1) {
i >>= 1;
data[i] = operation(data[i<<1|0], data[i<<1|1]);
}
}
T fold(int l, int r) {
l += n; r += n;
T resl = identity, resr = identity;
while (l < r) {
if (l & 1) resl = operation(resl, data[l++]);
if (r & 1) resr = operation(data[--r], resr);
l >>= 1; r >>= 1;
}
return operation(resl, resr);
}
T operator[](int i) { return data[n+i];}
};
const int INF = 1001001001;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, q;
cin >> n >> q;
vp a(n);
rep(i, n) {
int x;
cin >> x;
a[i] = P(x, i);
}
auto operation = [](P a, P b) { return a.fi < b.fi ? a : b;};
auto update = [](P a, P b) { return b;};
SegmentTree<P> seg(P(INF, -1), operation, update);
seg.build(a);
while (q--) {
int com, l, r;
cin >> com >> l >> r;
l--; r--;
if (com == 1) {
int tmpl = seg[l].fi, tmpr = seg[r].fi;
seg.set(l, P(tmpr, l));
seg.set(r, P(tmpl, r));
} else {
cout << seg.fold(l, r+1).se + 1 << endl;
}
}
}
lorent_kyopro