結果

問題 No.875 Range Mindex Query
ユーザー kya_skikya_ski
提出日時 2020-05-07 15:34:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,664 bytes
コンパイル時間 1,551 ms
コンパイル使用メモリ 171,868 KB
実行使用メモリ 5,484 KB
最終ジャッジ日時 2023-09-16 07:53:47
合計ジャッジ時間 4,137 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

template<typename T>
struct SegmentTree {
    using F = function<T(T, T)>;
private : 
    const T id;
    const F f;
    int n;
    vector<T> node;

public : 
    SegmentTree (const F &f, const T &id) : 
        f(f), id(id) { }

    void init (int sz) {
        assert(0 < sz);
        n = 1;
        while (n < sz) n <<= 1;
        node.resize(2*n, id);
    }

    void build (vector<T> v) {
        init((int)v.size());
        for (int i = 0; i < (int)v.size(); i++) node[i+n] = v[i];
        for (int i = n-1; i > 0; i--) node[i] = f(node[i<<1|0], node[i<<1|1]);
    }

    void update (int i, const T &x) {
        assert((i += n) < node.size());
        node[i] = x;
        while (i > 0) {
            i >>= 1;
            node[i] = f(node[i<<1], node[i<<1|1]);
        }
    }

    const T fold (int l, int r) const {
        assert(l <= r);
        T vl = id, vr = id;
        for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
            if (l&1) vl = f(vl, node[l++]);
            if (r&1) vr = f(node[--r], vr);
        }
        return f(vl, vr);
    }

    const T &operator[] (int i) const {
        assert(i += n < node.size());
        return node[i];
    }

};

int main() {
	int n, q;
	cin >> n >> q;
	vector<int> a(n), b(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	a.emplace_back(INT_MAX);
	iota(b.begin(), b.end(), 0);
	
	auto f = [&] (int l, int r) { return (a[l] < a[r] ? l : r); };
	SegmentTree<int> seg(f, n);
	seg.build(b);
	
	while (q--) {
		int op, l, r;
		cin >> op >> l >> r;
		l--; r--;
		if (op == 1) swap(a[l], a[r]);
		else cout << seg.fold(l, r + 1) + 1 << '\n';
	}
	
	return 0;
}
0