結果
| 問題 | No.875 Range Mindex Query |
| コンテスト | |
| ユーザー |
momohara
|
| 提出日時 | 2019-11-04 17:31:54 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 233 ms / 2,000 ms |
| コード長 | 2,814 bytes |
| コンパイル時間 | 934 ms |
| コンパイル使用メモリ | 97,620 KB |
| 実行使用メモリ | 7,936 KB |
| 最終ジャッジ日時 | 2024-09-14 23:45:47 |
| 合計ジャッジ時間 | 3,485 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 18 |
ソースコード
#include <iostream>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>
using namespace std;
#define MOD 1000000007
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
//グラフ関連
struct Edge {//グラフ
ll to, cap, rev;
Edge(ll _to, ll _cap, ll _rev) {
to = _to; cap = _cap; rev = _rev;
}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
G[from].push_back(Edge(to, cap, (ll)G[to].size()));
if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}
class RmqTree {
private:
P _find(ll a, ll b, ll k, ll l, ll r) {
//区間[l,r)の最小値を持つk番目のノードを探索
if (r <= a || b <= l)return make_pair(INF,-1); // 交差しない
if (a <= l && r <= b)return dat[k]; // 完全に含む
else {
P s1 = _find(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子
P s2 = _find(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子
return min(s1, s2);
}
}
public:
ll n, height;
vector<P> dat;
// 初期化(_nは最大要素数)
RmqTree(ll _n) {
n = 1;
height = 1;
while (n < _n) {
n *= 2;
height++;
}
dat = vector<P>(2 * n - 1, make_pair(INF,-1));
}
// i番目の値(0-indexed)をxに変更
void update(ll i, ll x) {
i += n - 1; // i番目の葉ノードへ
dat[i] = make_pair(x,i-(n-1));
while (i > 0) { // 登りながら更新
i = (i - 1) / 2;//親ノードのインデックス
dat[i] = min(dat[i * 2 + 1], dat[i * 2 + 2]);
//子ノードの小さい方の値を代入
}
}
// 区間[a,b)の最小値の取得
P find(ll a, ll b) {
return _find(a, b, 0, 0, n);
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
ll n, q;
cin >> n >> q;
Array a(n, 0);
RmqTree tree(n);
REP(i, n) {
cin >> a[i];
tree.update(i, a[i]);
}
REP(i, q) {
ll qq,l,r;
cin >> qq>>l>>r;
l--; r--;
if (qq == 1) {
swap(a[l],a[r]);
tree.update(l, a[l]);
tree.update(r, a[r]);
}
else {
cout << tree.find(l, r + 1).second+1 << endl;
}
}
return 0;
}
momohara