結果

問題 No.875 Range Mindex Query
ユーザー Ogtsn99Ogtsn99
提出日時 2019-09-08 18:41:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 291 ms / 2,000 ms
コード長 2,095 bytes
コンパイル時間 1,738 ms
コンパイル使用メモリ 173,796 KB
実行使用メモリ 9,056 KB
最終ジャッジ日時 2023-09-09 22:36:23
合計ジャッジ時間 4,762 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 205 ms
8,212 KB
testcase_12 AC 169 ms
6,224 KB
testcase_13 AC 142 ms
8,476 KB
testcase_14 AC 144 ms
8,596 KB
testcase_15 AC 193 ms
8,432 KB
testcase_16 AC 263 ms
8,660 KB
testcase_17 AC 291 ms
9,056 KB
testcase_18 AC 276 ms
8,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
struct SegTree{
    int n;
    vector <pair <int,int> > node;
    SegTree(vector <int> v){
        int sz = v.size();
        n = 1;
        while(n<sz) n*=2;
        node.resize(2*n-1, {INF,INF});
        for(int i=0; i<sz; i++) node[i+n-1] = {v[i],i}; //一番下側
        for(int i=n-2;i>=0;i--) node[i] = min(node[2*i+1], node[2*i+2]);
    }
    int getnum(int p){
        return node[n-1+p].F;
    }
    int geti(int p){
        return node[n-1+p].S;
    }
    void update(int number, int val){
        number += n-1;
        node[number].F= val;
        while(number>0){
            number=(number-1)/2;
            node[number] = min(node[number*2+1], node[number*2+2]);
        }
    }
    pair <int,int> getmin(int a, int b, int k=0, int l = 0, int r = -1){
        
        if(r<0) r=n;
        if(r<=a||b<=l) return {INF,INF};
        if(a <= l&& r<=b) return node[k];
        pair <int,int>  vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        pair <int,int>  vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
    }
    void showall(){
        for(int i=0;i<2*n-1;i++)cout<<node[i].F<<'&'<<node[i].S<<endl;
    }
};
//参考:http://tsutaj.hatenablog.com/entry/2017/03/29/204841
signed main(void){
    int n,q; cin>>n>>q;
    vector <int> a(n); 
    rep(i,n) cin>>a[i];
    SegTree t(a);
    //t.showall();
    rep(i, q){
        int b,l,r; cin>>b>>l>>r;
        l--; r--;
        if(b==1){
            int tmpl = t.getnum(l), tmpr = t.getnum(r);
            //cout<<tmpl<<' '<<tmpr<<endl;
            //cout<<t.geti(l)<<' '<<t.geti(r)<<endl;
            t.update(r, tmpl);
            t.update(l,tmpr);
        }else{
            cout<<t.getmin(l,r+1).S+1<<endl;
        }
    }
    //t.showall();
    //rep(i, 3) cout<<t.getnum(i)<<' '<<t.geti(i)<<endl;;
}
0