結果

問題 No.875 Range Mindex Query
ユーザー minatominato
提出日時 2020-01-04 04:29:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 192 ms / 2,000 ms
コード長 2,359 bytes
コンパイル時間 2,055 ms
コンパイル使用メモリ 190,052 KB
実行使用メモリ 6,016 KB
最終ジャッジ日時 2024-05-02 07:53:53
合計ジャッジ時間 4,156 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 128 ms
5,888 KB
testcase_12 AC 106 ms
5,376 KB
testcase_13 AC 89 ms
5,888 KB
testcase_14 AC 86 ms
6,016 KB
testcase_15 AC 115 ms
5,888 KB
testcase_16 AC 169 ms
5,888 KB
testcase_17 AC 192 ms
5,888 KB
testcase_18 AC 177 ms
5,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

struct SegmentTree {
    int N;
    vector<pair<int, int>> node;
    SegmentTree(vector<int> v) {
        N = 1;
        int sz = v.size();
        while (N < sz) N *= 2;
        node.assign(2*N,make_pair(N+1,N+1));
        for (int i = 0; i < sz; i++) node[i+N] = make_pair(v[i],i+1);
        for (int i = N-1; i > 0; i--) {
            if (node[i<<1|0].first < node[i<<1|1].first) {
                node[i] = node[i<<1|0];
            } else node[i] = node[i<<1|1];
        }
    }

    void update(int x, int y) {
        x += N; y += N;
        swap(node[x].first,node[y].first);
        while (x > 1) {
            x >>= 1;
            if (node[x<<1|0].first < node[x<<1|1].first) {
                node[x] = node[x<<1|0];
            } else node[x] = node[x<<1|1];
        }
        while (y > 1) {
            y >>= 1;
            if (node[y<<1|0].first < node[y<<1|1].first) {
                node[y] = node[y<<1|0];
            } else node[y] = node[y<<1|1];
        }
    }

    pair<int, int> getmin(int a, int b, int k = 1, int l = 0, int r = -1) {
        if (r < 0) r = N;
        if (a >= r || b <= l) return make_pair(N+1,N+1);
        if (a <= l && r <= b) return node[k];

        int vl,ln,vr,rn;
        tie(vl,ln) = getmin(a,b,k<<1|0,l,(l+r)/2);
        tie(vr,rn) = getmin(a,b,k<<1|1,(l+r)/2,r);

        if (vl < vr) return make_pair(vl,ln);
        else return make_pair(vr,rn);
    }
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,Q; cin >> N >> Q;
    vector<int> A(N);
    rep(i,N) cin >> A[i];

    SegmentTree sg(A);
    rep(i,Q) {
        int q,l,r; cin >> q >> l >> r;
        if (q == 1) sg.update(l-1,r-1);
        else cout << sg.getmin(l-1,r).second << endl;
    }
}
0