結果

問題 No.875 Range Mindex Query
ユーザー uchiiiiuchiiii
提出日時 2020-07-25 10:10:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,354 bytes
コンパイル時間 3,493 ms
コンパイル使用メモリ 228,952 KB
実行使用メモリ 5,692 KB
最終ジャッジ日時 2023-09-09 05:45:03
合計ジャッジ時間 5,375 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 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 AC 86 ms
5,388 KB
testcase_17 WA -
testcase_18 AC 86 ms
5,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma region
#pragma GCC target("avx2")
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define endl "\n"
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define ALL(x) (x).begin(), (x).end()
constexpr int INF=1<<30; constexpr ll LINF=1LL<<60; constexpr ll mod=1e9+7; constexpr int NIL = -1;
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
#pragma endregion
//-------------------

struct SegmentTree {
private:
    int n;
    vector<PII> node;
public:
    SegmentTree(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--) segchmin(i);
    }
    void segchmin(int i) {
        if(chmin(node[i].first, node[2*i+1].first)) node[i] = node[2*i+1];
        if(chmin(node[i].first, node[2*i+2].first)) node[i] = node[2*i+2];
    }
    void update(int i, int val) {
        i += n-1;
        node[i].first = val;
        while(i>0) {
            i = (i-1)/2;
            segchmin(i);
        }
    }
    void swap(int i, int j) {
        int val_i = node[i+n-1].first;
        int val_j = node[j+n-1].first;
        update(i, val_j);
        update(j, val_i);
    }

    PII get(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        if(r <= a or b <= l) return {INF, INF};
        if(a <= l and r <= b) return node[k];
        auto vl = get(a,b, 2*k+1, l, (l+r)/2);
        auto vr = get(a,b, 2*k+2, (l+r)/2, r);
        return vl.first < vr.first? vl: vr;
    }
};

int main(){
    cin.tie(0); ios::sync_with_stdio(false); //cout << fixed << setprecision(15);
    int n,Q; cin >> n >> Q;
    vector<int> v(n);
    rep(i,0,n) cin >> v[i];
    SegmentTree seg(v);
    while(Q--) {
        int num, l, r; cin >> num >> l >> r;
        l--, r--;
        if(num==1) {
            seg.swap(l,r);
        } else {
            cout << seg.get(l,++r).second+1 << endl;
        }
    }
    return 0;
}
0