Submission #440375

#TimeUsernameProblemLanguageResultExecution timeMemory
440375VladMBridges (APIO19_bridges)C++14
0 / 100
603 ms3756 KiB
#include <bits/stdc++.h> using namespace std; #define DIM 50007 #define INF 1000000007 int n, m, u, v, w[DIM], t[4*DIM], it, s, W, l, r, mid, L, R, mn, q, T; void BuildTree(int v, int tl, int tr) { if(tl==tr) { t[v]=w[tl]; return; } int tm=(tl+tr)>>1; BuildTree(2*v+1, tl, tm); BuildTree(2*v+2, tm+1, tr); t[v]=min(t[2*v+1], t[2*v+2]); return; } void update(int v, int tl, int tr, int x, int val) { if(x<tl || tr<x) return; if(tl==tr) { t[v]=val; return; } int tm=(tl+tr)>>1; update(2*v+1, tl, tm, x, val); update(2*v+2, tm+1, tr, x, val); t[v]=min(t[2*v+1], t[2*v+2]); return; } int get_min(int v, int tl, int tr, int L, int R) { if(tr<L || R<tl) return INF; if(L<=tl && tr<=R) return t[v]; int tm=(tl+tr)>>1; int mn1=get_min(2*v+1, tl, tm, L, R); int mn2=get_min(2*v+2, tm+1, tr, L, R); return min(mn1, mn2); } int main() { cin>>n>>m; for(int i=1; i<=m; i++) { cin>>u>>v>>w[i]; } BuildTree(0, 1, m); cin>>q; while(q--) { cin>>T; if(T==1) { cin>>it>>r; update(0, 1, m, it, r); continue; } cin>>s>>W; if(s==n) R=n; else { l=s; r=m; while(l<r) { mid=(l+r+1)>>1; mn=get_min(0, 1, m, s, mid); if(mn<W) r=mid-1; else l=mid; } if(l==s) { mn=get_min(0, 1, m, s, s); if(mn>=W) R=s+1; else R=s; } else { R=l+1; } } if(s==1) L=1; else { l=1; r=s-1; while(l<r) { mid=(l+r)>>1; mn=get_min(0, 1, n, 1, mid); if(mn<W) l=mid+1; else r=mid; } if(l==s-1) { mn=get_min(0, 1, n, l, l); if(mn<W) L=s; else L=s-1; } else L=l; } cout<<R-L+1<<endl; } return 0; }
#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...