結果

問題 No.875 Range Mindex Query
ユーザー frmon60frmon60
提出日時 2019-09-21 15:20:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 94 ms / 2,000 ms
コード長 2,106 bytes
コンパイル時間 2,851 ms
コンパイル使用メモリ 192,760 KB
実行使用メモリ 6,092 KB
最終ジャッジ日時 2023-10-19 03:20:33
合計ジャッジ時間 4,803 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 3 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 92 ms
5,828 KB
testcase_12 AC 73 ms
4,772 KB
testcase_13 AC 64 ms
6,092 KB
testcase_14 AC 63 ms
5,828 KB
testcase_15 AC 86 ms
6,092 KB
testcase_16 AC 87 ms
6,092 KB
testcase_17 AC 94 ms
6,092 KB
testcase_18 AC 92 ms
6,092 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> P; typedef pair<Int,Int> Pl;
const int mod = 1e9+7;
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) v.begin(),v.end()
#define Pr(type) priority_queue<type>
#define gPr(type) priority_queue<type,vector<type>,greater<type>>
#define V(type) vector<type>
#define rep(i,n) for(int i=0; i<n; i++)
#define rer(i,st,en) for(int i=st; i<en; i++)
#define gnr(i,l,r) for(int i=int(r)-1; i>=int(l); i--)
#define eb emplace_back
#define pri1(a) cout<<a<<'\n'
#define pri2(a,n) rep(i,n)cout<<a[i]<<'\n'
#define pri3(a,n) rep(i,n-1)cout<<a[i]<<' '; cout<<a[n-1]<<'\n'
#define prip(p) cout<<p.first<<' '<<p.second<<'\n'
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<class T,class F>
struct SegTree{
	V(T) buf;
	int s;
	const F f;
	const T g;
	SegTree(const V(T)& d,F ff,T gg):f(ff),g(gg){
		int n=d.size();
		s=1;
		while(s<n)s*=2;
		buf.resize(s*2,g);
		rep(i,n)
			buf[i+s]=d[i];
		gnr(i,1,s)
			u(i);
	}
	void u(int i){
		buf[i]=f(buf[i*2],buf[i*2+1]);
	}
	void set(int i,T t){
		i+=s;
		buf[i]=t;
		while(i>>=1)u(i);
	}
	T get(int b,int e,int l,int r,int i){
		if(e<=l||r<=b)return g;
		if(b<=l&&r<=e)return buf[i];
		int m=(l+r)/2;
		return f(get(b,e,l,m,i*2),get(b,e,m,r,i*2+1));
	}
	T get(int b,int e){
		return get(b,e,0,s,1);
	}
  T operator[](const int &k)const{
    return buf[k+s];
  }
};
template<class T,class F>
SegTree<T,F> segtree(const V(T)& d,F f,T g){
	return SegTree<T,F>(d,f,g);
}

int n,m,_,x,y,q,key;
string s,sb;
bool ok;



int main(){
  cin.tie(nullptr); ios::sync_with_stdio(false);

  cin>>n>>q; V(P) a(n);
  rep(i,n){cin>>x; a[i]=P(x,i+1);}
  auto seg=segtree(a,[](P x,P y){return min(x,y);},P(1e6,1e6));
  //rep(i,n)prip(seg[i]);
  rep(i,q){
    cin>>m>>x>>y; x--;
    if(m==2)pri1(seg.get(x,y).second);
    else{y--; swap(a[x].first,a[y].first); seg.set(x,a[x]); seg.set(y,a[y]);}
  }
}
0