結果

問題 No.875 Range Mindex Query
ユーザー ForestedForested
提出日時 2020-07-28 10:06:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 68 ms / 2,000 ms
コード長 2,886 bytes
コンパイル時間 930 ms
コンパイル使用メモリ 97,628 KB
実行使用メモリ 6,180 KB
最終ジャッジ日時 2023-09-11 06:21:07
合計ジャッジ時間 2,909 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 68 ms
5,648 KB
testcase_12 AC 56 ms
4,772 KB
testcase_13 AC 50 ms
5,860 KB
testcase_14 AC 48 ms
5,748 KB
testcase_15 AC 66 ms
5,912 KB
testcase_16 AC 59 ms
5,892 KB
testcase_17 AC 66 ms
5,896 KB
testcase_18 AC 63 ms
6,180 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// Template
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <cmath>
#include <complex>
#define rep(i, x) for (int i = 0; i < (x); ++i)
#define rng(i, x, y) for (int i = (x); i < (y); ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003;
template <typename T> inline bool chmin(T &x, const T &y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T &x, const T &y) {if (x < y) {x = y; return 1;} return 0;}
void solve();
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    solve();
    return 0;
}

// Segment Tree
template <typename Operator>
struct SegmentTree {
    Operator OP;
    using TypeNode = decltype(OP.NodeE);
    int length;
    vector<TypeNode> node;
    SegmentTree (int N) {
        length = 1;
        while (length < N) length <<= 1;
        node.assign(length << 1, OP.NodeE);
    }
    SegmentTree (vector<TypeNode> &vec) {
        length = 1;
        while (length < sz(vec)) length <<= 1;
        node.assign(2 * length, OP.NodeE);
        rep(i, sz(vec)) node[i + length] = vec[i];
        for (int i = length - 1; i > 0; --i) node[i] = OP.func(node[(i << 1) + 0], node[(i << 1) + 1]);
    }
    void update(int idx, TypeNode val) {
        idx += length;
        node[idx] = OP.change(node[idx], val);
        while (idx >>= 1) node[idx] = OP.func(node[(idx << 1) + 0], node[(idx << 1) + 1]);
    }
    TypeNode get(int l, int r) {
        l += length;
        r += length;
        TypeNode vl = OP.NodeE, vr = OP.NodeE;
        while (r > l) {
            if (l & 1) vl = OP.func(vl, node[l++]);
            if (r & 1) vr = OP.func(node[--r], vr);
            l >>= 1;
            r >>= 1;
        }
        return OP.func(vl, vr);
    }
};

struct hoge {
    using NodeType = pair<int, int>;
    NodeType NodeE = pair<int, int>(inf, -1);
    NodeType func(NodeType x, NodeType y) {return min(x, y);}
    NodeType change(NodeType x, NodeType y) {return y;}
};



// Main Code
void solve() {
    int n, q;
    cin >> n >> q;
    vector<pair<int, int>> a(n);
    rep(i, n) {
        cin >> a[i].first;
        a[i].second = i;
    }
    
    SegmentTree<hoge> ST(a);
    rep(_, q) {
        int num, l, r;
        cin >> num >> l >> r;
        --l; --r;
        if (num == 1) {
            auto a = ST.node[l + ST.length], b = ST.node[r + ST.length];
            a.second = r; b.second = l;
            ST.update(l, b); ST.update(r, a);
        } else {
            auto a = ST.get(l, r + 1);
            cout << a.second + 1 << "\n";
        }
    }
    return;
}
0