結果

問題 No.875 Range Mindex Query
ユーザー 0214sh70214sh7
提出日時 2019-09-06 21:54:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,886 bytes
コンパイル時間 1,620 ms
コンパイル使用メモリ 166,440 KB
実行使用メモリ 9,672 KB
最終ジャッジ日時 2023-09-06 23:40:48
合計ジャッジ時間 5,581 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

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
    
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]=INT_MAX;
    return n;
}
int Seg_calc(int a,int b){
    return min(a,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 INT_MAX;
    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 N,Q;
    int A[114514];
    int B[114514];
    int x[114514],l[114514],r[114514];
    cin >> N >> Q;
    REP(i,N){
        cin >> A[i];
    }
    
    B[0]=INF;
    REP(i,N){
        B[A[i]]=i;
    }
    
    REP(i,Q){
        cin >> x[i] >> l[i] >> r[i];
        l[i]--;r[i]--;
    }
    
    Seg_init(N);
    REP(i,N){
        Seg_update(i,A[i]);
    }
    //REP(i,N+1){cout << B[i] << " ";}cout << endl;
    REP(i,Q){
        if(x[i]==1){
            swap(A[l[i]],A[r[i]]);
            swap(B[A[l[i]]],B[A[r[i]]]);
            Seg_update(l[i],A[l[i]]);
            Seg_update(r[i],A[r[i]]);
        }else{
            int Ans = Seg_query(l[i],r[i]+1,0,0,N);
            cout << B[Ans]+1 << endl;
        }
    }
    //REP(i,N+1){cout << B[i] << " ";}cout << endl;
    
  return 0;
}

0