結果

問題 No.875 Range Mindex Query
ユーザー leaf_1415leaf_1415
提出日時 2019-09-06 21:25:40
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 104 ms / 2,000 ms
コード長 1,380 bytes
コンパイル時間 765 ms
コンパイル使用メモリ 78,908 KB
実行使用メモリ 8,136 KB
最終ジャッジ日時 2023-09-06 22:13:13
合計ジャッジ時間 2,728 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,140 KB
testcase_01 AC 5 ms
7,188 KB
testcase_02 AC 4 ms
7,184 KB
testcase_03 AC 3 ms
6,980 KB
testcase_04 AC 4 ms
7,140 KB
testcase_05 AC 4 ms
6,944 KB
testcase_06 AC 4 ms
7,000 KB
testcase_07 AC 5 ms
7,212 KB
testcase_08 AC 4 ms
7,140 KB
testcase_09 AC 4 ms
7,264 KB
testcase_10 AC 4 ms
6,980 KB
testcase_11 AC 104 ms
7,680 KB
testcase_12 AC 85 ms
7,800 KB
testcase_13 AC 77 ms
8,136 KB
testcase_14 AC 74 ms
7,652 KB
testcase_15 AC 101 ms
7,900 KB
testcase_16 AC 93 ms
8,000 KB
testcase_17 AC 102 ms
7,908 KB
testcase_18 AC 95 ms
7,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <utility>
#define llint long long
#define inf 1e18

using namespace std;
typedef pair<llint, llint> P;

struct SegTree{
	int size;
	vector<P> seg;
	
	SegTree(){}
	SegTree(int size){
		this->size = size;
		seg.resize(1<<(size+1));
	}
	
	void init()
	{
		for(int i = 0; i < (1<<(size+1)); i++) seg[i] = make_pair(inf, inf);
	}
	
	void update(int i, P val)
	{
		i += (1 << size);
		seg[i] = val;
		while(i > 1){
			i /= 2;
			seg[i] = min(seg[i*2], seg[i*2+1]);
		}
	}

	P query(int a, int b, int k, int l, int r)
	{
		if(b < l || r < a) return make_pair(inf, inf);
		if(a <= l && r <= b) return seg[k];
		P lval = query(a, b, k*2, l, (l+r)/2);
		P rval = query(a, b, k*2+1, (l+r)/2+1, r);
		return min(lval, rval);
	}
	P query(int a, int b)
	{
		return query(a, b, 1, 0, (1<<size)-1);
	}
};

llint n, Q;
llint a[100005];
SegTree seg(17);

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> Q;
	for(int i = 1; i <= n; i++) cin >> a[i];
	
	seg.init();
	for(int i = 1; i <= n; i++) seg.update(i, make_pair(a[i], i));
	
	llint t, l, r;
	for(int q = 0; q < Q; q++){
		cin >> t >> l >> r;
		if(t == 1){
			llint x = seg.query(l, l).first, y = seg.query(r, r).first;
			seg.update(l, make_pair(y, l)), seg.update(r, make_pair(x, r));
		}
		else{
			cout << seg.query(l, r).second << "\n";
		}
	}
	flush(cout);
	return 0;
}
0