結果

問題 No.875 Range Mindex Query
ユーザー llllltwwwwwllllltwwwww
提出日時 2019-09-19 22:35:54
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,627 bytes
コンパイル時間 606 ms
コンパイル使用メモリ 73,152 KB
実行使用メモリ 5,608 KB
最終ジャッジ日時 2023-09-28 12:14:47
合計ジャッジ時間 3,912 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
#include<map>
#include<set>
#include <climits>
using namespace std;
#define INF 11000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;

const int MAX_N=1<<17;

//セグメント木を持つグローバル配列
int n;
ll dat[2*MAX_N-1];

//初期化
void init(int n_){
    //簡単のために要素数を2のべき乗に
    n=1;
    while(n<n_) n*=2;

    //全ての値をINT_MAXに
    for(int i=0;i<2*n-1;i++) dat[i]=2147483647;
}

//k番目の値(0-indexed)をaに変更
void update(int k,ll a){
    //葉の節点
    k+=n-1;
    dat[k]=a;
    //登りながら更新
    while(k>0){
        k=(k-1)/2;
        dat[k]=min(dat[k*2+1],dat[k*2+2]);
    }
}

//[a,b)の最小値を求める
//後ろの方の引数は、計算の簡単のための引数
//kは接点の番号、l,rはその接点が[l,r)に対応づいていることを表す
//したがって、外からはquery(a,b,0,0,n)として呼ぶ
ll query(int k,int l,int r){
    if(l+1==r) return k;
    if(dat[k]==dat[k*2+1]) return query(k*2+1,l,(l+r)/2);
    else return query(k*2+2,(l+r)/2,r);
}

int main(){
    int N,Q,com,l,r;
    ll a;
    cin>>N>>Q;
    init(N);

    for(int i=0;i<N;i++){
        cin>>a;
        update(i,a);
    }

    for(int i=0;i<Q;i++){
        cin>>com>>l>>r;
        l--;r--;
        if(com==1){
            a=dat[l+n-1];
            update(l,dat[r+n-1]);
            update(r,a);
        }else{
            cout<<query(0,0,n)+2-n<<endl;;
        }
    }
}
0