結果
| 問題 | 
                            No.3116 More and more teleporter
                             | 
                    
| コンテスト | |
| ユーザー | 
                             umezo
                         | 
                    
| 提出日時 | 2025-04-19 18:07:30 | 
| 言語 | C++23  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 133 ms / 2,000 ms | 
| コード長 | 1,674 bytes | 
| コンパイル時間 | 3,317 ms | 
| コンパイル使用メモリ | 280,752 KB | 
| 実行使用メモリ | 8,600 KB | 
| 最終ジャッジ日時 | 2025-04-19 18:07:36 | 
| 合計ジャッジ時間 | 5,967 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 22 | 
ソースコード
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
#include<bits/stdc++.h>
using namespace std;
template <class T> using V=vector<T>;
template <class T> using VV=V<V<T>>;
template <typename X>
struct SegTree{
  using FX=function<X(X,X)>;
  int n;
  FX fx;
  const X ex;
  vector<X> dat;
  SegTree(int n_,FX fx_,X ex_) : n(),fx(fx_),ex(ex_),dat(n_*4,ex_){
    int x=1;
    while(n_>x) x*=2;
    n=x;
  }
  void set(int i,X x){dat[i+n-1]=x;}
  void build(){
    for(int k=n-2;k>=0;k--) dat[k]=fx(dat[2*k+1],dat[2*k+2]);
  }
  void update(int i,X x){
    i+=n-1;
    dat[i]=x;
    while(i>0){
      i=(i-1)/2;
      dat[i]=fx(dat[i*2+1],dat[i*2+2]);
    }
  }
  X get(int i){return dat[i+n-1];}
  X all(){return dat[0];}
  X query(int a,int b){ return query_sub(a,b,0,0,n);}
  X query_sub(int a,int b,int k,int l,int r){
    if(r<=a || b<=l) return ex;
    else if(a<=l && r<=b) return dat[k];
    else{
      X vl=query_sub(a,b,k*2+1,l,(l+r)/2);
      X vr=query_sub(a,b,k*2+2,(l+r)/2,r);
      return fx(vl,vr);
    }
  }
};
int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n,q;
  cin>>n>>q;
  
  using XX=int;
  auto fx=[](XX x1,XX x2)->XX{return min(x1,x2);};
  XX ex=1e9+7;
  SegTree<XX> lseg(n,fx,ex),rseg(n,fx,ex);
  
  while(q--){
    int c;
    cin>>c;
    if(c==1){
      int x;
      cin>>x;
      x--;
      auto tmp=min(lseg.query(0,x+1)+x,rseg.query(x,n)-x);
      tmp=min(tmp,x);
      cout<<tmp<<'\n';
    }
    else{
      int x,c;
      cin>>x>>c;
      x--;
      if(lseg.get(x)>c-x) lseg.update(x,c-x);
      if(rseg.get(x)>c+x) rseg.update(x,c+x);
    }
  }
      
  return 0;
}
            
            
            
        
            
umezo