結果

問題 No.875 Range Mindex Query
ユーザー furafura
提出日時 2020-06-01 03:28:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,168 bytes
コンパイル時間 2,326 ms
コンパイル使用メモリ 205,928 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-30 17:36:14
合計ジャッジ時間 4,356 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int A[100000];

class segment_tree{
	int n;
	vector<int> dat;
	int query(int l,int r,int a,int b,int u){
		if(l<=a && b<=r) return dat[u];
		int res=-1;
		int c=(a+b)/2;
		if(l<c && a<r){
			int tmp=query(l,r,a,c,2*u+1);
			if(res==-1 || A[res]>A[tmp]) res=tmp;
		}
		if(l<b && c<r){
			int tmp=query(l,r,c,b,2*u+2);
			if(res==-1 || A[res]>A[tmp]) res=tmp;
		}
		return res;
	}
public:
	segment_tree(int N){
		for(n=1;n<N;n*=2);
		dat.assign(2*n-1,0);
	}
	void update(int u,int val){
		u+=n-1;
		dat[u]=val;
		while(u>0){
			u=(u-1)/2;
			if(A[dat[2*u+1]]<=A[dat[2*u+2]]){
				dat[u]=dat[2*u+1];
			}
			else{
				dat[u]=dat[2*u+2];
			}
		}
	}
	int query(int l,int r){ return query(l,r,0,n,0); }
};

int main(){
	int n; scanf("%d",&n);
	rep(i,n) scanf("%d",&A[i]);

	segment_tree ST(n);
	rep(i,n) ST.update(i,i);

	int q; scanf("%d",&q);
	rep(_,q){
		int type,l,r; scanf("%d%d%d",&type,&l,&r); l--; r--;
		if(type==1){
			int i=ST.query(l,l+1);
			int j=ST.query(r,r+1);
			ST.update(l,j);
			ST.update(r,i);
		}
		else{
			printf("%d\n",ST.query(l,r)+1);
		}
	}

	return 0;
}
0