結果

問題 No.875 Range Mindex Query
ユーザー reg7777reg7777
提出日時 2019-09-08 15:32:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 211 ms / 2,000 ms
コード長 1,441 bytes
コンパイル時間 1,681 ms
コンパイル使用メモリ 174,804 KB
実行使用メモリ 6,016 KB
最終ジャッジ日時 2023-09-09 22:31:28
合計ジャッジ時間 4,272 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 137 ms
5,604 KB
testcase_12 AC 116 ms
4,604 KB
testcase_13 AC 97 ms
6,016 KB
testcase_14 AC 96 ms
5,732 KB
testcase_15 AC 131 ms
5,948 KB
testcase_16 AC 198 ms
5,900 KB
testcase_17 AC 211 ms
5,916 KB
testcase_18 AC 204 ms
5,996 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h> 

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF INT_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

struct Seg{
  vector<pii>node;
  int treesz;
  int vsz;
  Seg(vector<int>v){
    int n=v.size();
    vsz=1;while(vsz<n)vsz*=2;
    treesz=2*vsz-1;
    node.resize(treesz,{INF,0});
    for(int i=0;i<n;i++)node[vsz-1+i]={v[i],i};
    for(int i=vsz-2;i>=0;i--)node[i]=min(node[2*i+1],node[2*i+2]);
  }
  pii operator[](int i){
    return node[vsz-1+i];
  }
  void update(int x,int i){
    node[vsz-1+i]={x,i};
    i+=vsz-1;
    while(i>0){
      i=(i-1)/2;
      node[i]=min(node[2*i+1],node[2*i+2]);
    }
  }
  pii getmin(int a,int b,int k=0,int l=0,int r=-1){
    if(r<0)r=vsz;
    if(r<=a||b<=l)return {INF,0};
    if(a<=l&&r<=b)return node[k];
    pii lv=getmin(a,b,2*k+1,l,(r+l)/2);
    pii rv=getmin(a,b,2*k+2,(r+l)/2,r);
    return min(lv,rv);
  }
};

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N,Q;
  cin>>N>>Q;
  vector<int>a(N);
  for(int i=0;i<N;i++)cin>>a[i];
  Seg seg(a);
  for(int i=0;i<Q;i++){
    int n,l,r;
    cin>>n>>l>>r;
    if(n==1){
      int lmemo=seg[l-1].first;
      int rmemo=seg[r-1].first;
      seg.update(rmemo,l-1);
      seg.update(lmemo,r-1);
    }
    if(n==2){
      pii ans=seg.getmin(l-1,r);
      cout<<ans.second+1<<endl;
    }
  }
  return 0;
}
0