結果

問題 No.875 Range Mindex Query
ユーザー first_vilfirst_vil
提出日時 2019-09-11 14:51:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 2,878 bytes
コンパイル時間 1,646 ms
コンパイル使用メモリ 171,868 KB
実行使用メモリ 6,744 KB
最終ジャッジ日時 2023-09-15 13:48:26
合計ジャッジ時間 3,345 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 74 ms
6,292 KB
testcase_12 AC 61 ms
4,896 KB
testcase_13 AC 53 ms
6,436 KB
testcase_14 AC 52 ms
6,416 KB
testcase_15 AC 71 ms
6,420 KB
testcase_16 AC 77 ms
6,476 KB
testcase_17 AC 84 ms
6,692 KB
testcase_18 AC 80 ms
6,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
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 (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

struct p {int num, itr;};
bool operator < (const p& a, const p& b) { return a.num < b.num; }
bool operator > (const p& a, const p& b) { return a.num > b.num; }
bool operator == (const p& a, const p& b) { return a.num == b.num; }

template<class T>
class segtree {
    vector<T> dat;
    int n = 1;
public:
#define def {INF,-1}
    segtree(int _n){
        while (n < _n)n *= 2;
        dat.resize(2 * n - 1 , def);
    }
    segtree(vector<T> a) {
        int size = a.size();
        while (n < size)n *= 2;
        dat.resize(2 * n - 1, def);
        FOR(i, 0, size)dat[i + n - 1] = a[i];
        rFOR(i, 0, n - 1)dat[i] = fun(dat[2 * i + 1], dat[2 * i + 2]);
    }

    T fun(T x, T y) { return min(x, y); }

    void update(int i, T x) {
        i += n - 1;
        dat[i] = x;
        while (i > 0) {
            --i /= 2;
            dat[i] = fun(dat[i * 2 + 1], dat[i * 2 + 2]);
        }
    }

    T query(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l)return def;
        else if (a <= l && r <= b)return dat[k];
        else {
            T s = query(a, b, k * 2 + 1, l, (l + r) / 2);
            T t = query(a, b, k * 2 + 2, (l + r) / 2, r);
            return fun(s, t);
        }
    }
    T query(int a, int b) { return query(a, b, 0, 0, n); }

    void datswap(int a, int b) {
        a += n - 1, b += n - 1;
        swap(dat[a].num, dat[b].num);
        while (a > 0) {
            --a /= 2;
            dat[a] = fun(dat[a * 2 + 1], dat[a * 2 + 2]);
        }
        while (b > 0) {
            --b /= 2;
            dat[b] = fun(dat[b * 2 + 1], dat[b * 2 + 2]);
        }
    }
};

int main() {
    init();

    int n, q;
    cin >> n >> q;
    vector<p> in(n);
    FOR(i, 0, n) {
        cin >> in[i].num;
        in[i].itr = i;
    }
    segtree<p> seg(in);

    int num, l, r;
    while (q--) {
        cin >> num >> l >> r;
        if (num == 1)seg.datswap(--l, --r);
        else cout << seg.query(--l, r).itr+1 << "\n";
    }
}
0