結果
| 問題 |
No.875 Range Mindex Query
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-09-06 21:51:25 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 293 ms / 2,000 ms |
| コード長 | 2,191 bytes |
| コンパイル時間 | 1,025 ms |
| コンパイル使用メモリ | 93,368 KB |
| 実行使用メモリ | 10,368 KB |
| 最終ジャッジ日時 | 2024-06-24 17:37:41 |
| 合計ジャッジ時間 | 3,820 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 18 |
ソースコード
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
typedef pair<ll, int> P;
#define fs first
#define sc second
P min(P a, P b){
if(a.fs < b.fs){
return a;
} else {
return b;
}
}
class SegmentTree{
public:
int N;
vector<P> node;
P INF = P(1LL << 40, 100000000);
//コンストラクタ
SegmentTree(vector<P> v){
int sz = v.size();
N = 1;
while(N < sz) N *= 2;
node.resize(2 * N - 1, INF);
for(int i = 0; i < sz; i++){
int k = i + N - 1;
node[k] = v[i];
while(k > 0){
k = (k - 1) / 2;
node[k] = min(node[k * 2 + 1], node[k * 2 + 2]);
}
}
}
//k番目の値(0_indexed)をaに変更
void update(int k, P a){
//葉の節点
k += N - 1;
node[k] = a;
//登りながら更新
while(k > 0){
k = (k - 1) / 2;
node[k] = min(node[k * 2 + 1], node[k * 2 + 2]);
}
}
//[a,b)の最小値
P query(int a, int b){
return Query(a, b, 0, 0, N);
}
P Query(int a, int b, int k, int l, int r){
if(r <= a || b <= l) return INF;
if(a <= l && r <= b) return node[k];
else{
P v1 = Query(a, b, k * 2 + 1, l, (l + r) / 2);
P v2 = Query(a, b, k * 2 + 2, (l + r) / 2, r);
return min(v1, v2);
}
}
void print(){
for(int i = 0; i < 2 * N - 1; i++){
//cout << "node[" << i << "] " << node[i] << endl;
}
}
};
int main(){
int N, Q;
cin >> N >> Q;
vector<P> a(N);
for(int i = 0; i < N; i++){
ll tmp;
cin >> tmp;
a[i] = P(tmp, i);
}
SegmentTree sg = SegmentTree(a);
vector<int> ans;
for(int i = 0; i < Q; i++){
int q, l, r;
cin >> q >> l >> r;
l--;
r--;
if(q == 1){
P L = sg.query(l, l + 1);
P R = sg.query(r, r + 1);
sg.update(l, P(R.fs, L.sc));
sg.update(r, P(L.fs, R.sc));
} else {
//cout << (sg.query(l, r + 1)).sc << endl;
ans.push_back((sg.query(l, r + 1)).sc + 1);
}
}
for(int i : ans){
cout << i << endl;
}
return 0;
}