結果

問題 No.875 Range Mindex Query
ユーザー shop_oneshop_one
提出日時 2020-04-15 15:37:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 238 ms / 2,000 ms
コード長 1,658 bytes
コンパイル時間 910 ms
コンパイル使用メモリ 99,560 KB
実行使用メモリ 7,256 KB
最終ジャッジ日時 2023-07-24 23:23:15
合計ジャッジ時間 4,090 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 3 ms
4,380 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 171 ms
7,128 KB
testcase_12 AC 142 ms
5,192 KB
testcase_13 AC 123 ms
7,256 KB
testcase_14 AC 120 ms
7,252 KB
testcase_15 AC 162 ms
7,136 KB
testcase_16 AC 218 ms
7,132 KB
testcase_17 AC 238 ms
7,192 KB
testcase_18 AC 229 ms
7,120 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(18);
}
template <typename Monoid >
struct SegmentTree{
  using F = function< Monoid(Monoid,Monoid) >;

  int sz;
  vector<Monoid> seg;

  const F f;
  const Monoid M;

  SegmentTree(int n,const F f,const Monoid &M) : f(f),M(M){
    sz = 1;
    while(sz<n) sz<<=1;
    seg.assign(sz*2,M);
  }
  void set(int k,const Monoid &v){
    seg[k+sz] = v;
  }
  void build(){
    for(int k=sz-1;k>0;k--){
      seg[k] = f(seg[2*k],seg[2*k+1]);
    }
  }
  void update(int k,const Monoid &v){
    k += sz;
    seg[k] = v;
    while(k >>= 1){
      seg[k] = f(seg[2*k],seg[2*k+1]);
    }
  }
  Monoid que(int a,int b){
    Monoid L=M,R=M;
    for(a+=sz, b+=sz;a<b;a>>=1,b>>=1){
      if(a&1) L = f(L,seg[a++]);
      if(b&1) R = f(seg[--b],R);
    }
    return f(L,R);
  }
  Monoid operator[](const int &k) const{
    return seg[k+sz];
  }
};
signed main(){
  init_io();
  ll n,q,a,p,l,r;
  cin >> n >> q;
  SegmentTree<P> seg(n,[](P a,P b){
      return min(a,b);
      },P(11110000000,0));
  for(ll i=0;i<n;i++){
    cin >> a;
    seg.update(i,P(a,i));
  }
  for(int i=0;i<q;i++){
    cin >> p >> l >> r;
    l--;
    r--;
    if(p==1){
      ll x = seg[l].first;
      ll y = seg[r].first;
      seg.update(l,P(y,l));
      seg.update(r,P(x,r));
    }else{
      cout << seg.que(l,r+1).second+1<<endl;
    }
  }
}
0