Submission #769703

#TimeUsernameProblemLanguageResultExecution timeMemory
769703boyliguanhanBridges (APIO19_bridges)C++17
0 / 100
442 ms3984 KiB
#include <bits/stdc++.h> using namespace std; #define MAXN 400100 int n,m,q, l[MAXN], r[MAXN], v[MAXN]; void build(int i, int rl, int rr) { l[i] = rl, r[i] = rr; if(rl!=rr) build(i*2,rl,rl+rr>>1), build(i*2+1,rl+rr+2>>1,rr); } void upd(int i, int p, int x) { if(l[i]==r[i]) return (void)(v[i]=x); if(p>r[i*2]) upd(i*2+1,p,x); else upd(i*2,p,x); v[i]=min(v[i*2],v[i*2+1]); } int query(int i, int rl, int rr){ if(rl>r[i]||l[i]>rr) return 2e9; if(rl<=l[i]&&r[i]<=rr) return v[i]; return min(query(i*2,rl,rr),query(i*2+1,rl,rr)); } signed main() { cin >> n >> m; build(1,1,m); for(int i = 1; i <= m; i++) { int a; cin >> a >> a >> a; upd(1,i,a); } cin >> n; while(n--) { int a,b,c; cin>>a>>c>>b; if(a-1){ int l = 1, r = b, lpos; while(l<r) { int mid = l+r>>1; if(query(1,mid,b-1) >= c) r = mid; else l = mid+1; } lpos = l; l = b, r = n; while(l<r){ int mid = l+r+2>>1; if(query(1, b, mid-1) >= c) l = mid; else r = mid-1; } cout << r-lpos+1 << '\n'; } else upd(1,c,b); } }

Compilation message (stderr)

bridges.cpp: In function 'void build(int, int, int)':
bridges.cpp:8:24: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
    8 |         build(i*2,rl,rl+rr>>1),
      |                      ~~^~~
bridges.cpp:9:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
    9 |         build(i*2+1,rl+rr+2>>1,rr);
      |                     ~~~~~^~
bridges.cpp: In function 'int main()':
bridges.cpp:38:28: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   38 |                 int mid = l+r>>1;
      |                           ~^~
bridges.cpp:47:30: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   47 |                 int mid = l+r+2>>1;
      |                           ~~~^~
#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...