結果

問題 No.875 Range Mindex Query
ユーザー gasingasin
提出日時 2019-09-07 12:59:40
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 284 ms / 2,000 ms
コード長 1,785 bytes
コンパイル時間 749 ms
コンパイル使用メモリ 76,592 KB
実行使用メモリ 5,196 KB
最終ジャッジ日時 2023-09-08 15:40:12
合計ジャッジ時間 3,590 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 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,376 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 201 ms
5,064 KB
testcase_12 AC 166 ms
4,376 KB
testcase_13 AC 143 ms
5,196 KB
testcase_14 AC 141 ms
5,108 KB
testcase_15 AC 190 ms
5,196 KB
testcase_16 AC 261 ms
5,064 KB
testcase_17 AC 284 ms
5,108 KB
testcase_18 AC 274 ms
5,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <cstdio>
#include <string.h>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.1415926535897932;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

// 区間最小値、要素更新のsegtree

template<typename T>
struct segtree{
    int n;
    vector<T> dat;
    T unit;

    void init(int n_, T unit_) {
        unit = unit_;
        n = 1;
        while(n < n_) n *= 2;
        dat.assign(2*n-1, unit);
    }

    void update(int k, T 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,0,0,seg.n)で呼ぶ
    T query(int a, int b, int k, int l, int r){
        if(r <= a || b <= l) return unit;
        if(a <= l && r <= b) return dat[k];
        else{
            T vl = query(a,b,k*2+1,l,(l+r)/2);
            T vr = query(a,b,k*2+2,(l+r)/2,r);
            return min(vl, vr);
        }
    }
};

int n, q;
segtree<pi> seg;

int main() {
    cin >> n >> q;
    seg.init(n, pi(inf,inf));
    rep(i,n) {
        int a; cin >> a;
        seg.update(i, pi(a,i));
    }
    rep(i,q) {
        int f, l, r;
        cin >> f >> l >> r;
        l--; r--;
        if (f == 1) {
            pi lv = seg.dat[seg.n-1+l], rv = seg.dat[seg.n-1+r];
            seg.update(l, pi(rv.first,l));
            seg.update(r, pi(lv.first,r));
        } else {
            cout << seg.query(l, r+1, 0, 0, seg.n).second + 1 << endl;
        }
    }
}
0