結果

問題 No.875 Range Mindex Query
ユーザー ateate
提出日時 2019-09-06 22:08:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 224 ms / 2,000 ms
コード長 2,469 bytes
コンパイル時間 2,219 ms
コンパイル使用メモリ 209,068 KB
実行使用メモリ 8,896 KB
最終ジャッジ日時 2023-09-07 00:03:57
合計ジャッジ時間 4,751 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 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,380 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 150 ms
8,320 KB
testcase_12 AC 123 ms
5,888 KB
testcase_13 AC 101 ms
8,780 KB
testcase_14 AC 99 ms
8,460 KB
testcase_15 AC 141 ms
8,468 KB
testcase_16 AC 208 ms
8,572 KB
testcase_17 AC 224 ms
8,736 KB
testcase_18 AC 218 ms
8,896 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:76:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   76 | main(){
      | ^~~~

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(ll i=0;i<(n);++i)
#define reps(i,n) for(ll i=1;i<=(n);++i)
using ll = long long;
using str = string;
constexpr long long INF = (1LL<<60);
constexpr long long MOD = (1e9+7);
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
inline void dump(){cout<<endl;}
template<class Head,class... Tail>inline void dump(Head&& head, Tail&&... tail){cout<<head<<", ";dump(forward<Tail>(tail)...);}
template<typename T>inline istream &operator>>(istream&input,vector<T>&v){for(auto &elemnt:v)input>>elemnt;return input;}

// usi tree
class Segment_Tree {
private:
  ll n=1;
  using P=pair<ll,ll>;
  P init = P(INF,0);
  std::vector<P> node;
  P f(P x,P y){
    return x.first<y.first?x:y;
  }
public:
  Segment_Tree(std::vector<ll> v){
    ll sz = ((ll)v.size());    
    while(n<sz)n<<=1;
    node.resize(n*2-1,init);
    for(ll i=0;i<sz;++i)node[i+n-1]=P(v[i],i+1);
    for(ll i=n-2;i>=0;--i)node[i]=f(node[i*2+1],node[i*2+2]);
  }
  void update(ll idx,ll x){
    idx+=n-1;
    node[idx].first=x;
    while(idx){
      idx--;idx>>=1;
      node[idx]=f(node[idx*2+1],node[idx*2+2]);
    }
  }
  void swap(ll l,ll r){
    auto tmp=node[l+n-1].first;
    node[l+n-1].first=node[r+n-1].first;
    node[r+n-1].first=tmp;
    l+=n-1;
    r+=n-1;
    while(l){
      l--;l>>=1;
      node[l]=f(node[l*2+1],node[l*2+2]);
    }
    while(r){
      r--;r>>=1;
      node[r]=f(node[r*2+1],node[2*r+2]);
    }
  }
  auto query(ll a,ll b,ll k=0,ll l=0,ll r=-1){
    if(r<0)r=n;
    if(r<=a || b<=l)return init;
    if(a<=l && r<=b)return node[k];
    else{
      auto vl = query(a,b,2*k+1,l,(l+r)/2);
      auto vr = query(a,b,2*k+2,(l+r)/2,r);
      return f(vl,vr);
    }
  }
  void dump(){
    for(auto i:node)cout<<i.first<<" ";cout<<endl;
    for(auto i:node)cout<<i.second<<" ";cout<<endl;
  }
  
};

main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout<<fixed<<setprecision(10);
  
  ll n,q;
  cin>>n>>q;
  vector<ll> a(n);
  cin>>a;
  Segment_Tree seg(a);
  rep(i,q){
    ll x,l,r;
    cin>>x>>l>>r;
    l--;r--;
    if(x==1){
      seg.swap(l,r);
    }
    else{
      auto tmp=seg.query(l,r+1);
      cout<<tmp.second<<endl;
    }
  }
  
  
}
0