結果

問題 No.875 Range Mindex Query
ユーザー RubikunRubikun
提出日時 2019-09-06 23:52:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 289 ms / 2,000 ms
コード長 1,614 bytes
コンパイル時間 1,487 ms
コンパイル使用メモリ 165,084 KB
実行使用メモリ 6,564 KB
最終ジャッジ日時 2023-09-07 03:04:16
合計ジャッジ時間 4,555 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,492 KB
testcase_01 AC 3 ms
5,368 KB
testcase_02 AC 3 ms
5,500 KB
testcase_03 AC 2 ms
5,360 KB
testcase_04 AC 3 ms
5,544 KB
testcase_05 AC 2 ms
5,416 KB
testcase_06 AC 3 ms
5,440 KB
testcase_07 AC 3 ms
5,380 KB
testcase_08 AC 3 ms
5,384 KB
testcase_09 AC 3 ms
5,432 KB
testcase_10 AC 3 ms
5,540 KB
testcase_11 AC 206 ms
6,384 KB
testcase_12 AC 168 ms
6,160 KB
testcase_13 AC 149 ms
6,448 KB
testcase_14 AC 145 ms
6,396 KB
testcase_15 AC 197 ms
6,444 KB
testcase_16 AC 268 ms
6,564 KB
testcase_17 AC 289 ms
6,392 KB
testcase_18 AC 277 ms
6,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=998244353,MAX=1<<18,INF=1<<30;

int n,dat[2*MAX-1],ans[2*MAX-1];

void init(int n_){
    n=1;
    while(n<n_) n*=2;
    for(int i=0;i<2*n;i++){
        dat[i]=INF;
    }
    for(int i=2*n-2;i>=0;i--){
        if(i>=n-1) ans[i]=i-(n-1);
        else{
            if(dat[i*2+1]>dat[i*2+2]) ans[i]=ans[i*2+2];
            else ans[i]=ans[i*2+1];
        }
    }
}

void update(int k,int a){
    k+=n-1;
    dat[k]=a;
    
    while(k>0){
        k=(k-1)/2;
        if(dat[k*2+1]>dat[k*2+2]){
            dat[k]=dat[k*2+2];
            ans[k]=ans[k*2+2];
        }else{
            dat[k]=dat[k*2+1];
            ans[k]=ans[k*2+1];
        }
    }
}

int query(int a,int b,int k,int l,int r){
    
    if(r<=a||b<=l) return -1;
    if(a<=l&&r<=b) return ans[k];
    else{
        int vl=query(a,b,2*k+1,l,(l+r)/2);
        int vr=query(a,b,2*k+2,(l+r)/2,r);
        if(vl==-1) return vr;
        if(vr==-1) return vl;
        if(dat[n-1+vl]>dat[n-1+vr]) return vr;
        return vl;
    }
}

int main(){
    
    //std::ifstream in("text.txt");
    //std::cin.rdbuf(in.rdbuf());
    
    int N,Q;cin>>N>>Q;
    init(N);
    
    for(int i=0;i<N;i++){
        int a;cin>>a;
        update(i,a);
    }
    
    for(int i=0;i<Q;i++){
        int a,b,c;cin>>a>>b>>c;
        if(a==1){
            int d=dat[n-1+b-1],e=dat[n-1+c-1];
            //cout<<d<<" "<<e<<endl;
            update(b-1,e);
            update(c-1,d);
        }else{
            cout<<query(b-1,c,0,0,n)+1<<endl;
        }
    }
}
0