結果

問題 No.875 Range Mindex Query
ユーザー 0214sh70214sh7
提出日時 2019-09-06 21:47:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,755 bytes
コンパイル時間 1,407 ms
コンパイル使用メモリ 166,160 KB
実行使用メモリ 8,744 KB
最終ジャッジ日時 2023-09-06 23:27:56
合計ジャッジ時間 4,069 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << -1 << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

int N,Q;
int A[114514];
    
    
const int MAX_N=100010;
int n,dat[4*MAX_N-1];
int Seg_init(int n_){
    n=1;
    while(n<n_)n*=2;
    for(int i=0;i<2*n-1;++i)dat[i]=N;
    return n;
}
int Seg_calc(int a,int b){
    if(A[a]<A[b]){
        return a;
    }else{
        return b;
    }
}
void Seg_update(int k,int a){
    k+=n-1;
    dat[k]=a;
    while(k>0){
        k=(k-1)/2;
        dat[k]=Seg_calc(dat[2*k+1],dat[2*k+2]);
    }
}
int Seg_query(int a,int b,int k,int l,int r){
    if(r<=a||b<=l)return N;
    if(a<=l&&r<=b)return dat[k];
    int vl=Seg_query(a,b,2*k+1,l,(l+r)/2);
    int vr=Seg_query(a,b,2*k+2,(l+r)/2,r);
    return Seg_calc(vl,vr);
}



signed main(void){
    int x[114514],l[114514],r[114514];
    cin >> N >> Q;
    REP(i,N){
        cin >> A[i];
    }
    A[N]=INF;
    REP(i,Q){
        cin >> x[i] >> l[i] >> r[i];
        l[i]--;r[i]--;
    }
    
    Seg_init(N);
    REP(i,N){
        Seg_update(i,i);
    }
    //REP(i,2*n-1){cout << dat[i] << " ";}cout << endl;
    REP(i,Q){
        if(x[i]==1){
            int p=l[i],q=r[i];
            swap(A[p],A[q]);
            Seg_update(p,p);
            Seg_update(q,q);
        }else{
            int Ans=Seg_query(l[i],r[i]+1,0,0,N);
            cout << Ans+1 << endl;
        }
    }
  return 0;
}

0