結果

問題 No.875 Range Mindex Query
ユーザー beet
提出日時 2021-02-05 14:35:13
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,123 bytes
コンパイル時間 1,925 ms
コンパイル使用メモリ 199,568 KB
最終ジャッジ日時 2025-01-18 11:45:04
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other WA * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

// verification-helper: PROBLEM https://yukicoder.me/problems/3277
#include <bits/stdc++.h>
using namespace std;
#define call_from_test
template<typename T=int>
vector<T> read(size_t n){
vector<T> ts(n);
for(size_t i=0;i<n;i++) cin>>ts[i];
return ts;
}
template <typename T>
struct SegmentTree{
using F = function<T(T,T)>;
int n;
F f;
T ti;
vector<T> dat;
SegmentTree(F f,T ti):f(f),ti(ti){}
void init(int n_){
n=1;
while(n<n_) n<<=1;
dat.assign(n<<1,ti);
}
void build(const vector<T> &v){
int n_=v.size();
init(n_);
for(int i=0;i<n_;i++) dat[n+i]=v[i];
for(int i=n-1;i;i--)
dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
}
void set_val(int k,T x){
dat[k+=n]=x;
while(k>>=1)
dat[k]=f(dat[(k<<1)|0],dat[(k<<1)|1]);
}
T query(int a,int b){
if(a>=b) return ti;
T vl=ti,vr=ti;
for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1) {
if(l&1) vl=f(vl,dat[l++]);
if(r&1) vr=f(dat[--r],vr);
}
return f(vl,vr);
}
template<typename C>
int find(int st,C &check,T &acc,int k,int l,int r){
if(l+1==r){
acc=f(acc,dat[k]);
return check(acc)?k-n:-1;
}
int m=(l+r)>>1;
if(m<=st) return find(st,check,acc,(k<<1)|1,m,r);
if(st<=l and !check(f(acc,dat[k]))){
acc=f(acc,dat[k]);
return -1;
}
int vl=find(st,check,acc,(k<<1)|0,l,m);
if(~vl) return vl;
return find(st,check,acc,(k<<1)|1,m,r);
}
template<typename C>
int find(int st,C &check){
T acc=ti;
return find(st,check,acc,1,0,n);
}
};
#undef call_from_test
signed main(){
cin.tie(0);
ios::sync_with_stdio(0);
const char newl = '\n';
int n,q;
cin>>n>>q;
auto as=read(n);
auto f=[](int a,int b){return min(a,b);};
SegmentTree<int> seg(f,n+1);
seg.build(as);
for(int i=0;i<q;i++){
int t,l,r;
cin>>t>>l>>r;
if(t==1){
l--;r--;
swap(as[l],as[r]);
seg.set_val(l,as[l]);
seg.set_val(r,as[r]);
}
if(t==2){
l--;
int m=seg.query(l,r);
auto check=[&](int x){return x==m;};
cout<<seg.find(l,check)+1<<newl;
}
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0