Submission #248938

#TimeUsernameProblemLanguageResultExecution timeMemory
248938tc_abdBridges (APIO19_bridges)C++14
0 / 100
435 ms524292 KiB
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0) #define It it=se.begin();it!=se.end();it++ #define mem(dp,i) memset(dp,i,sizeof(dp)) #define all(x) begin(x),end(x) #define unmap unordered_map #define pii pair<int,int> #include <bits/stdc++.h> #define pll pair<ll,ll> #define vll vector<ll> #define vi vector<int> #define ld long double #define ll long long #define pb push_back #define sh short int #define mid (l+r)/2 #define S second #define F first #define sqr 447 using namespace std; const ll inf = 1e18; const int mod = 1e9+7; const ld pai=acos(-1); ll n,m,q; ll w[50009]; ll tree[200009]; void build(ll node,ll l,ll r){ if(l == r) return void(tree[node]=w[l]); build(node*2,l,mid),build(node*2+1,mid+1,r); tree[node] = min(tree[node*2],tree[node*2+1]); } void upd(ll node,ll l,ll r,ll k,ll val){ if(l == r) return void(tree[node]=val); if(k <= mid) upd(node*2,l,mid,k,val); else upd(node*2+1,mid+1,r,k,val); tree[node] = min(tree[node*2],tree[node*2+1]); } ll query(ll node,ll l,ll r,ll s,ll e){ if(s <= l && e >= r) return tree[node]; if(s <= mid && e > mid){ return min(query(node*2,l,mid,s,e),query(node*2+1,mid+1,r,s,e)); } if(s <= mid) return query(node*2,l,mid,s,e); return query(node*2+1,mid+1,r,s,e); } ll bin1(ll node,ll val){ ll l = node,r = n; while(r-l > 1){ if(query(1,0,n-2,node,mid-1) >= val) l = mid; else r = mid; } return l-node; } ll bin2(ll node,ll val){ ll l = -1,r = node; while(r-l > 1){ if(query(1,0,n-2,mid,node-1) >= val) r = mid; else l = mid; } return node-r; } int main(){ fast,cin>>n>>m; for(int i=0;i<m;i++){ ll a,b,c; cin>>a>>b>>c; w[i] = c; } build(1,0,n-2); cin>>q; while(q--){ ll t,a,b; cin>>t>>a>>b; if(t == 1) upd(1,0,n-2,a-1,b); else cout<<bin1(a-1,b)+bin2(a-1,b)+1<<endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...