제출 #1364886

#제출 시각아이디문제언어결과실행 시간메모리
1364886mrasool1665Bridges (APIO19_bridges)C++20
0 / 100
172 ms3536 KiB
//MRasool kheyri
//iran -> khorasan -> ferdows -> Baghestan
//14/2/1405
//vasat azmoonima...
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
#define el '\n'
#define mid (l+r)/2
#define lid id<<1
#define rid lid|1
const ll maxn = 1e6 + 100 ;
const ll oo = 1e17 + 100 ;
ll n , m ,q  ;
vector<ll> vec ;
ll node[maxn] ;
void merge(ll l , ll r , ll id){
    node[id] = min(node[lid],node[rid]) ;
    return ;
}
void build(ll l , ll r , ll id){
    if(l+1 == r){
        node[id] = vec[l] ;
        return ;
    }
    build(l,mid,lid) ;
    build(mid,r,rid) ;
    merge(l,r,id) ;
    return ;
}
void update(ll s , ll e , ll l , ll r , ll id , ll x){
    if(e <= l || r <= s){return;}
    if(s <= l && r <= e){
        node[id] = x ;
        return ;
    }
    update(s,e,l,mid,lid,x) ;
    update(s,e,mid,r,rid,x) ;
    merge(l,r,id) ;
    return ;
}
ll get(ll s , ll e , ll l , ll r , ll id , ll typ , ll w){
    if(e <= l || r <= s){
        return oo ;
    }
    if(s <= l && r <= e){
        if(l+1 == r){
            return l ;
        }
        if(typ == 0){
            if(node[rid] <= w){
                return get(s,e,l,mid,lid,typ,w) ;
            }
            else{
                return get(s,e,mid,r,rid,typ,w) ;
            }
        }
        else{
            if(node[lid] <= w){
                return get(s,e,mid,r,rid,typ,w) ;
            }
            else{
                return get(s,e,l,mid,lid,typ,w) ;
            }
        }
    }
    return min(get(s,e,l,mid,lid,typ,w),get(s,e,mid,r,rid,typ,w)) ;
}
void solve(){
    cin>>n>>m ;
    for(ll i = 0 ; i < m ; i++){
        ll u , v , w ;
        cin>>u>>v>>w ;
        u-- ; v-- ;
        vec.push_back(w) ;
    }
    build(0,vec.size(),1) ;
    cin>>q ;
    for(ll _ = 0 ; _ < q ; _++){
        ll typ ;
        cin>>typ ;
        if(typ == 1){
            ll x , y ;
            cin>>x>>y ;
            x-- ;
            vec[x] = y ;
            update(x,x+1,0,vec.size(),1,y) ;
        }
        else{
            ll x , y ;
            cin>>x>>y ;
            x-- ;
            ll ans = 1 ;
            if(x != 0 && y <= vec[x-1]){
                ans += x-get(0,x,0,vec.size(),1,0,y) ;
            }
            if(x != n-1 && y <= vec[x]){
                ans += get(x,vec.size(),0,vec.size(),1,1,y)-x+1 ;
            }
            cout<<ans<<el ;
        }
    }
    return ;
}
int main(){
    //ios_base::sync_with_stdio(0) , cin.tie(nullptr) , cout.tie(nullptr) ;
    ll t = 1 ;
    //cin>>t ;
    while(t--){
        solve() ;
    }
    return 0 ;
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…