結果
| 問題 | No.875 Range Mindex Query |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-09-06 21:23:08 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 114 ms / 2,000 ms |
| コード長 | 1,581 bytes |
| 記録 | |
| コンパイル時間 | 1,762 ms |
| コンパイル使用メモリ | 173,080 KB |
| 実行使用メモリ | 7,808 KB |
| 最終ジャッジ日時 | 2024-06-24 16:15:08 |
| 合計ジャッジ時間 | 3,740 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 18 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
#define N (1<<18)
template<class T>
struct RMQ{
pair<T,int>dat[2*N];
T inf;
function<pair<T,int>(pair<T,int>,pair<T,int>)>merge;
RMQ(T Inf,function<pair<T,int>(pair<T,int>,pair<T,int>)>Merge){
inf=Inf;merge=Merge;
rep(i,2*N-1){
dat[i].first=inf;
if(i>=N-1)dat[i].second=i-N+1;
}
}
void update(int k,T x){
k+=N-1;
dat[k].first=x;
while(k){
k=(k-1)/2;
dat[k]=merge(dat[k*2+1],dat[k*2+2]);
}
}
pair<T,int>query(int a,int b,int k=0,int l=0,int r=N){
if(b<=l||r<=a)return make_pair(inf,-1);
if(a<=l&&r<=b)return dat[k];
auto lb=query(a,b,k*2+1,l,(l+r)/2);
auto rb=query(a,b,k*2+2,(l+r)/2,r);
return merge(lb,rb);
}
T getValue(int a,int b){
return query(a,b).first;
}
int getIndex(int a,int b){
return query(a,b).second;
}
};
template<class T>
pair<T,int>RangeMax(pair<T,int>a,pair<T,int>b){
return a.first>=b.first?a:b;
}
template<class T>
pair<T,int>RangeMin(pair<T,int>a,pair<T,int>b){
return a.first<=b.first?a:b;
}
RMQ<int>seg(INT_MAX,RangeMin<int>);
int main(){
int n,q;cin>>n>>q;
rep(i,n){
int a;scanf("%d",&a);
seg.update(i,a);
}
rep(i,q){
int t;scanf("%d",&t);
if(t==2){
int l,r;scanf("%d%d",&l,&r);l--;
printf("%d\n",seg.getIndex(l,r)+1);
}
else{
int l,r;scanf("%d%d",&l,&r);l--;
int x=seg.getValue(l,l+1),y=seg.getValue(r-1,r);
seg.update(l,y);seg.update(r-1,x);
}
}
}