結果

問題 No.875 Range Mindex Query
ユーザー lorent_kyoprolorent_kyopro
提出日時 2020-05-22 21:59:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 207 ms / 2,000 ms
コード長 2,755 bytes
コンパイル時間 2,571 ms
コンパイル使用メモリ 201,960 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 16:47:11
合計ジャッジ時間 5,251 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 3 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 3 ms
6,940 KB
testcase_08 AC 3 ms
6,944 KB
testcase_09 AC 3 ms
6,940 KB
testcase_10 AC 3 ms
6,940 KB
testcase_11 AC 139 ms
6,940 KB
testcase_12 AC 113 ms
6,944 KB
testcase_13 AC 95 ms
6,944 KB
testcase_14 AC 95 ms
6,944 KB
testcase_15 AC 136 ms
6,940 KB
testcase_16 AC 188 ms
6,944 KB
testcase_17 AC 207 ms
6,940 KB
testcase_18 AC 198 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

template <typename T>
struct SegmentTree {
    using F = function<T(T, T)>;
    int n;
    vector<T> data;
    T identity;
    F operation;
    F update;
    SegmentTree(T _identity, F _operation, F _update)
        : identity(_identity), operation(_operation), update(_update) {}
    void init(int _n) {
        n = 1;
        while (n < _n) n <<= 1;
        data.assign(n<<1, identity);
    }
    void build(const vector<T> &v) {
        int _n = (int)v.size();
        init(_n);
        for (int i = 0; i < _n; ++i) data[n+i] = v[i];
        for (int i = n-1; i >= 0; --i) {
            data[i] = operation(data[i<<1|0], data[i<<1|1]);
        }    
    }
    void set(int i, T x) {
        i += n;
        data[i] = update(data[i], x);
        while (i > 1) {
            i >>= 1;
            data[i] = operation(data[i<<1|0], data[i<<1|1]);
        }
    }
    T fold(int l, int r) {
        l += n; r += n;
        T resl = identity, resr = identity;
        while (l < r) {
            if (l & 1) resl = operation(resl, data[l++]);
            if (r & 1) resr = operation(data[--r], resr);
            l >>= 1; r >>= 1;
        }
        return operation(resl, resr);
    }
    T operator[](int i) { return data[n+i];}
};

const int INF = 1001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, q;
    cin >> n >> q;
    vp a(n);
    rep(i, n) {
        int x;
        cin >> x;
        a[i] = P(x, i);
    }
    auto operation = [](P a, P b) { return a.fi < b.fi ? a : b;};
    auto update = [](P a, P b) { return b;};
    SegmentTree<P> seg(P(INF, -1), operation, update);
    seg.build(a);
    while (q--) {
        int com, l, r;
        cin >> com >> l >> r;
        l--; r--;
        if (com == 1) {
            int tmpl = seg[l].fi, tmpr = seg[r].fi;
            seg.set(l, P(tmpr, l));
            seg.set(r, P(tmpl, r));
        } else {
            cout << seg.fold(l, r+1).se + 1 << endl;
        }
    }
}
0