結果
問題 | No.875 Range Mindex Query |
ユーザー |
👑 |
提出日時 | 2022-07-25 21:33:03 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 229 ms / 2,000 ms |
コード長 | 3,650 bytes |
コンパイル時間 | 1,252 ms |
コンパイル使用メモリ | 116,836 KB |
最終ジャッジ日時 | 2025-01-30 14:03:19 |
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 18 |
ソースコード
//yukicoder@cpp17 #include <iostream> #include <cmath> #include <algorithm> #include <iomanip> #include <string> #include <vector> #include <set> #include <stack> #include <queue> #include <map> #include <bitset> #include <complex> #include <cctype> #include <utility> #include <climits> #include <numeric> using namespace std; using ll = long long; using P = pair<ll,ll>; const ll MOD = 998244353; const ll MODx = 1000000007; const int INF = (1<<30)-1; const ll LINF = (1LL<<62LL)-1; const double EPS = (1e-10); P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}}; P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}}; template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); } template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); } /* 確認ポイント cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる 計算量は変わらないが楽できるシリーズ min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる */ /* function corner below */ template< typename T, typename F> struct SegmentTree{ private: int n; vector<T> node; F f; T initer; public: SegmentTree(int n_, F f, T initer) : f(f),initer(initer) { n = 1; while(n < n_)n*=2; node.resize(2*n-1, initer); } SegmentTree(int n_, F f,T initer, vector<T> x) : f(f),initer(initer) { n = 1; while(n < n_)n*=2; node.resize(2*n-1, initer); set(x); } void set(vector<T> x){ for(int i = 0; n > i; i++){ update(i,x[i]); } } void update(int x, T val){ x += (n-1); node[x] = val; while(x > 0){ x = (x-1)/2; node[x] = f(node[2*x+1],node[2*x+2]); } } void add(int x, T val){ x += (n-1); node[x] += val; while(x > 0){ x = (x-1)/2; node[x] = f(node[2*x+1],node[2*x+2]); } } T getf(int a,int b, int k=0, int l=0, int r=-1){ if(r < 0){ r = n-1; } if(r < a || b < l){ return initer; } if(a <= l && r <= b){ return node[k]; } T vl = getf(a,b,2*k+1,l,(l+r)/2); T vr = getf(a,b,2*k+2,(l+r)/2+1,r); return f(vl,vr); } }; template <typename T, typename F> SegmentTree<T, F> get_segment_tree(int N, const F &f, T initer){ return SegmentTree<T,F>{N,f,initer}; } template <typename T, typename F> SegmentTree<T, F> get_segment_tree(int N, const F &f, T initer, vector<T> x){ return SegmentTree<T,F>{N,f,initer,x}; } /* Function corner above */ __attribute__((constructor)) void initial() { cin.tie(0); ios::sync_with_stdio(false); } int main(){ int n,q;cin>>n>>q; vector<pair<int,int>> A(n); for(int i = 0; n > i; i++){ cin>>A[i].second; A[i].first = i+1; } auto B = get_segment_tree(n,[](pair<int,int> a, pair<int,int> b){ if(a.second < b.second)return a; else return b; }, {200000,200000},A); for(int _ = 0; q > _; _++){ int x;cin>>x; if(x == 1){ int a,b;cin>>a>>b;a--;b--; auto a_ = B.getf(a,a); auto b_ = B.getf(b,b); B.update(a,{a_.first,b_.second}); B.update(b,{b_.first,a_.second}); }else{ int l,r;cin>>l>>r;l--;r--; auto x = B.getf(l,r); cout << x.first << endl; } } }