結果
| 問題 |
No.875 Range Mindex Query
|
| コンテスト | |
| ユーザー |
ate
|
| 提出日時 | 2019-09-06 22:08:19 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 261 ms / 2,000 ms |
| コード長 | 2,469 bytes |
| コンパイル時間 | 2,569 ms |
| コンパイル使用メモリ | 204,328 KB |
| 最終ジャッジ日時 | 2025-01-07 16:50:40 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 18 |
コンパイルメッセージ
main.cpp:76:1: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type]
76 | main(){
| ^~~~
ソースコード
#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;
}
}
}
ate