結果
| 問題 |
No.875 Range Mindex Query
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-10-05 21:37:39 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,396 bytes |
| コンパイル時間 | 643 ms |
| コンパイル使用メモリ | 71,808 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-19 22:14:34 |
| 合計ジャッジ時間 | 4,177 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 1 |
| other | WA * 18 |
ソースコード
#include <iostream>
#include <limits>
#include <vector>
using namespace std;
//Compiler version g++ 6.3.0
template<typename T> class RMQ{
private:
const T INF = numeric_limits<T>::max();
T n;
vector<T> dat;
T sub_query(T a,T b,T k,T l,T r){
if(a >= r || b <= l){
return INF;
}else if(a <= l && r <= b){
return dat[k];
}else{
T tx = sub_query(a,b,2*k+1,l,(l+r)/2);
T ty = sub_query(a,b,2*k+2,(l+r)/2,r);
return min(tx,ty);
}
}
public:
RMQ(int _n):n(),dat(4*_n,INF){
T x(1);
while(_n > x){
x *= 2;
}
n = x;
}
void update(T i,T x){
i += n-1;
dat[i] = x;
while(i > 0){
i = (i-1)/2;
dat[i] = min(dat[2*i+1],dat[2*i+2]);
}
}
T query(T a,T b){
return sub_query(a,b,0,0,n);
}
void change(T i,T j){
T tmp = dat[i];
(*this).update(i,dat[j]);
(*this).update(j,tmp);
}
};
int main(){
int n,q;
cin >> n >> q;
RMQ<int> a(n);
for(int i=0;i < n;i++){
int x;
cin >> x;
a.update(i,x);
}
for(int i=0;i < q;i++){
int t;
cin >> t;
if(t == 1){
int l,r;
cin >> l >> r;
a.change(l,r);
}else if(t == 2){
int l,r;
cin >> l >> r;
cout << a.query(l,r) << endl;
}
}
return 0;
}