Submission #440397

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