結果

問題 No.875 Range Mindex Query
ユーザー chocoruskchocorusk
提出日時 2019-09-06 21:28:36
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 269 ms / 2,000 ms
コード長 1,799 bytes
コンパイル時間 791 ms
コンパイル使用メモリ 105,740 KB
実行使用メモリ 6,748 KB
最終ジャッジ日時 2023-09-06 22:33:00
合計ジャッジ時間 3,514 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 3 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,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 198 ms
6,428 KB
testcase_12 AC 163 ms
4,872 KB
testcase_13 AC 139 ms
6,408 KB
testcase_14 AC 135 ms
6,536 KB
testcase_15 AC 184 ms
6,452 KB
testcase_16 AC 247 ms
6,456 KB
testcase_17 AC 269 ms
6,748 KB
testcase_18 AC 254 ms
6,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<typename Monoid>
struct SegmentTree{
	using F=function<Monoid(Monoid, Monoid)>;
	int sz;
	vector<Monoid> seg;
	const F f;
	const Monoid e;

	SegmentTree(int n, const F f, const Monoid &e): f(f), e(e){
		sz=1;
		while(sz<n) sz<<=1;
		seg.resize(2*sz, e);
	}

	SegmentTree(int n, const F f, const Monoid &e, vector<Monoid> v): f(f), e(e){
		sz=1;
		while(sz<n) sz<<=1;
		seg.resize(2*sz, e);
		for(int i=0; i<n; i++) seg[i+sz]=v[i];
		for(int i=sz-1; i>=1; i--){
			seg[i]=f(seg[2*i], seg[2*i+1]);
		}
	}

	void update(int k, const Monoid &x){
		k+=sz;
		seg[k]=x;
		while(k>1){
			k>>=1;
			seg[k]=f(seg[2*k], seg[2*k+1]);
		}
	}

	Monoid query(int a, int b){
		a+=sz, b+=sz;
		Monoid ret=e;
		for(;a<b; a>>=1, b>>=1){
			if(b&1) ret=f(ret, seg[--b]);
			if(a&1) ret=f(ret, seg[a++]);
		}
		return ret;
	}

	Monoid operator[](const int &k) const{
		return seg[k+sz];
	}
};
int main()
{
	int n, q; cin>>n>>q;
	vector<P> a(n);
	for(int i=0; i<n; i++){
		cin>>a[i].first;
		a[i].second=i;
	}
	SegmentTree<P> seg(n, [](P a, P b){ return min(a, b);}, P(n+1, n+1), a);
	for(int i=0; i<q; i++){
		int l, r, t; cin>>t>>l>>r; l--; r--;
		if(t==1){
			int x=seg[l].first, y=seg[r].first;
			seg.update(l, P(y, l));
			seg.update(r, P(x, r));
		}else{
			cout<<seg.query(l, r+1).second+1<<endl;
		}
	}
	return 0;
}
0