Submission #27792

#TimeUsernameProblemLanguageResultExecution timeMemory
27792TAMREFPalembang Bridges (APIO15_bridge)C++11
22 / 100
173 ms12180 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int mx=1e5+5; ll Q[mx], R[mx], M[mx], C[mx<<1]; ll ans; int K,N,U; struct BIT{ ll a[mx<<1]; BIT(){ for(int i=0;i<mx<<1;i++) a[i]=0; } ll s(int i){ ll f=0; for(int j=i;j;j-=j&-j) f+=a[j]; return f; } void u(int i,ll v){ for(int j=i;j<mx<<1;j+=j&-j) a[j]+=v; } }; void input(){ scanf("%d %d",&K,&N); char s,t; for(int i=1;i<=N;i++){ getchar(); scanf("%c %d %c %d",&s,&Q[i],&t,&R[i]); if(s==t){ ans+=llabs(Q[i]-R[i]); --i,--N; } else{ ++ans; if(s=='B') swap(Q[i],R[i]); M[i]=Q[i]+R[i]; C[2*i-1]=Q[i]; C[2*i]=R[i]; } } sort(C+1,C+2*N+1); U=unique(C+1,C+2*N+1)-C; for(int i=1;i<=N;i++) Q[i]=lower_bound(C+1,C+U,Q[i])-C, R[i]=lower_bound(C+1,C+U,R[i])-C; } struct solver1{ BIT x,y,cx,cy; ll tx,ty; ll pro(int t){ int cxs=cx.s(t),cys=cy.s(t); ll xs=x.s(t), ys=y.s(t); return (C[t]*cxs-xs)+((tx-xs)-C[t]*(N-cxs)) +(C[t]*cys-ys)+((ty-ys)-C[t]*(N-cys)); } void solve(){ for(int i=1;i<=N;i++){ x.u(Q[i],C[Q[i]]); y.u(R[i],C[R[i]]); cx.u(Q[i],1); cy.u(R[i],1); } tx=x.s(U-1), ty=y.s(U-1); int p=1,q,r,s=U-1; while(p<s){ q=p+(s-p)/3, r=s-(s-p)/3; if(pro(q)<=pro(r)) s=r-1; else p=q+1; } printf("%lld\n",ans+pro(p)); } } S1; int main(){ input(); if(K==1) S1.solve(); else return 0; }

Compilation message (stderr)

bridge.cpp: In function 'void input()':
bridge.cpp:27:46: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'll* {aka long long int*}' [-Wformat=]
         scanf("%c %d %c %d",&s,&Q[i],&t,&R[i]);
                                              ^
bridge.cpp:27:46: warning: format '%d' expects argument of type 'int*', but argument 5 has type 'll* {aka long long int*}' [-Wformat=]
bridge.cpp:23:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&K,&N);
                         ^
bridge.cpp:27:47: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%c %d %c %d",&s,&Q[i],&t,&R[i]);
                                               ^
#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...