結果

問題 No.875 Range Mindex Query
ユーザー kotatsugamekotatsugame
提出日時 2019-09-07 02:19:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 300 ms / 2,000 ms
コード長 1,388 bytes
コンパイル時間 756 ms
コンパイル使用メモリ 79,264 KB
実行使用メモリ 4,476 KB
最終ジャッジ日時 2023-09-07 07:19:41
合計ジャッジ時間 3,882 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 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 3 ms
4,380 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 203 ms
4,380 KB
testcase_12 AC 166 ms
4,376 KB
testcase_13 AC 147 ms
4,380 KB
testcase_14 AC 143 ms
4,380 KB
testcase_15 AC 202 ms
4,380 KB
testcase_16 AC 275 ms
4,464 KB
testcase_17 AC 300 ms
4,476 KB
testcase_18 AC 289 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:52:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   52 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
using namespace std;
#include<vector>
#include<functional>
#include<limits>
template<typename T>
struct segtree{
	function<T(T,T)>calcfn,updatefn;
	int n;
	T defvalue;
	vector<T>dat;
	segtree(int n_=0,T defvalue_=numeric_limits<T>::max(),
		function<T(T,T)>calcfn_=[](T a,T b){return a<b?a:b;},
		function<T(T,T)>updatefn_=[](T a,T b){return b;}
	):defvalue(defvalue_),calcfn(calcfn_),updatefn(updatefn_)
	{
		n=1;
		while(n<n_)n<<=1;
		dat.assign(2*n-1,defvalue);
	}
	void copy(const vector<T>&v)
	{
		for(int i=0;i<v.size();i++)dat[i+n-1]=v[i];
		for(int i=n-2;i>=0;i--)dat[i]=calcfn(dat[i*2+1],dat[i*2+2]);
	}
	void update(int i,T a)
	{
		i+=n-1;
		dat[i]=updatefn(dat[i],a);
		while(i>0)
		{
			i=(i-1)/2;
			dat[i]=calcfn(dat[2*i+1],dat[2*i+2]);
		}
	}
	T query(int a,int b,int i=0,int l=0,int r=-1)//[a,b)
	{
		if(r<0)r=n;
		if(r<=a||b<=l)return defvalue;
		else if(a<=l&&r<=b)return dat[i];
		else
		{
			return calcfn(
				query(a,b,i*2+1,l,(l+r)/2),
				query(a,b,i*2+2,(l+r)/2,r)
			);
		}
	}
};
int N,Q;
int A[1<<17];
main()
{
	cin>>N>>Q;
	segtree<int>P(N,N,[](int a,int b){return A[a]<A[b]?a:b;});
	for(int i=0;i<N;i++)
	{
		cin>>A[i];
		P.update(i,i);
	}
	A[N]=N+1;
	for(int i=0;i<Q;i++)
	{
		int c,l,r;cin>>c>>l>>r;
		l--,r--;
		if(c==1)
		{
			swap(A[l],A[r]);
			P.update(l,l);
			P.update(r,r);
		}
		else
		{
			cout<<P.query(l,r+1)+1<<endl;
		}
	}
}
0