結果

問題 No.875 Range Mindex Query
ユーザー kenta255kenta255
提出日時 2019-09-06 21:46:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,027 bytes
コンパイル時間 2,049 ms
コンパイル使用メモリ 203,384 KB
実行使用メモリ 8,756 KB
最終ジャッジ日時 2023-09-06 23:26:54
合計ジャッジ時間 6,060 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,756 KB
testcase_01 AC 3 ms
4,380 KB
testcase_02 AC 4 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 4 ms
4,380 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e18)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))


template <typename T>
struct RMQ{// 0-index
	int n,rn,bn; // rn個のかたまりをbn個
	vector<T> data,bucket,indbucket;
	RMQ(int n_){init(n_);}
	void init(int n_){
		n = n_;
		rn = sqrt(n);
		bn = ceil((double)n/rn);
		data.resize(n,0);
		bucket.resize(bn,0);
		indbucket.resize(bn,0);
	}
	T get(int i){
		return data[i]+bucket[i/rn];
	}
	int get_index(int l,int r){
		int res = -1;
		int minx = 300000000;
		FOR(j,l,r+1){
			if(j%rn==0 && (j+rn)<=r){
				if(minx>bucket[j/rn]){
					minx = bucket[j/rn];
					res = indbucket[j/rn];
				}
			}else{
				if(minx>data[j]){
					minx = data[j];
					res = j;
				}
			}
		}
		return res;
	}
	void change(int i,T x){ //i番目をxに
		data[i] = x;
		int ind = i/rn;
		bucket[ind] = 300000000;
		FOR(j,ind*rn,(ind+1)*rn){
			if(bucket[ind]>data[j]){
				bucket[ind] = data[j];
				indbucket[ind] = j;
			}
		}
	}
};


int main(){
	int N,a,Q;
	cin >> N >> Q;
	RMQ<int> rmq(N+2);
	FOR(i,0,N){
		cin >> a;
		rmq.change(i+1,a);
	}
	FOR(i,0,Q){
		int q,l,r;
		cin >> q >> l >> r;
		if(q==1){
			int al = rmq.data[l];
			int ar = rmq.data[r];
			rmq.change(l,ar);
			rmq.change(r,al);
		}else{
			cout << rmq.get_index(l,r) << endl;
		}
	}
}
0