結果

問題 No.875 Range Mindex Query
ユーザー zelnyokzelnyok
提出日時 2019-12-08 10:21:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 256 ms / 2,000 ms
コード長 1,941 bytes
コンパイル時間 787 ms
コンパイル使用メモリ 88,812 KB
実行使用メモリ 8,624 KB
最終ジャッジ日時 2023-08-28 15:34:42
合計ジャッジ時間 4,216 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 3 ms
4,376 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 3 ms
4,376 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 187 ms
7,156 KB
testcase_12 AC 157 ms
6,308 KB
testcase_13 AC 133 ms
8,048 KB
testcase_14 AC 131 ms
7,696 KB
testcase_15 AC 180 ms
8,420 KB
testcase_16 AC 236 ms
8,360 KB
testcase_17 AC 256 ms
8,176 KB
testcase_18 AC 247 ms
8,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define ENDL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */

const int INF = 1e9;

struct S
{
	int x,y;
	S() {}
	S(int x,int y) : x(x),y(y) {}
	static S I() {
		return S(INF,-1);
	}
	void merge(S& a, S& b) {
		if(a.x<b.x) {
			x=a.x; y=a.y;
		} else {
			x=b.x; y=b.y;
		}
	}
};

struct SegmentTree
{
	const int n;
	std::vector<S> data;
	SegmentTree(int n, std::vector<S>& a) : n(n), data(2*n) {
		for(int i=0;i<n;i++) {
			data[n+i] = a[i];
		}
		for(int i=n-1;i>0;i--) {
			data[i].merge(data[i<<1], data[i<<1|1]);
		}
	}
	void set(int i, S v) {
		data[n+i] = v;
		i+=n;
		while(i>0) {
			i>>=1;
			data[i].merge(data[i<<1], data[i<<1|1]);
		}
	}
	S get(int l, int r) {
		// 0-Indexed, [l, r)
		l+=n; r+=n;
		S sum = S::I();
		while(l<r) {
			if(l&1) sum.merge(sum,data[l++]);
			if(r&1) sum.merge(sum,data[--r]);
			l>>=1; r>>=1;
		}
		return sum;
	}
};


signed main() {
	int n,q;
	std::cin >> n >> q;
	std::vector<int> a(n);
	rep(i,n) std::cin >> a[i];
	std::vector<S> b(n);
	rep(i,n) b[i] = S(a[i],i+1);
	SegmentTree s(n,b);
	rep(qqq,q) {
		int x;
		std::cin >> x;
		int l,r;
		std::cin >> l >> r;
		if(x==1) {
			S lx = s.get(l-1,l);
			S rx = s.get(r-1,r);
			lx.y = r; rx.y = l;
			s.set(r-1,lx); s.set(l-1,rx);
		} else {
			print(s.get(l-1,r).y);
		}
	}
	return 0;
}
0