제출 #42574

#제출 시각아이디문제언어결과실행 시간메모리
42574fefePalembang Bridges (APIO15_bridge)C++14
0 / 100
5 ms3388 KiB
#include<bits/stdc++.h> #define MAX_N 100005 #define inf (1LL<<60) #define pb push_back #define fi first #define se second using namespace std; typedef long long LL; typedef pair<LL,LL> pil; struct node{ LL cnt,sum; node *l,*r; node(LL cnt,LL sum,node *l,node *r):cnt(cnt),sum(sum),l(l),r(r){} node *update(LL idx,LL p,LL x){ if(idx<0) return new node(cnt+x,sum+x*p,NULL,NULL); if(p>>idx&(1LL)) return new node(cnt+x,sum+x*p,l,r->update(idx-1,p,x)); return new node(cnt+x,sum+x*p,l->update(idx-1,p,x),r); } }*R1,*R2; LL n,k,m; LL ans,aa; pil arr[MAX_N]; pil serch(LL idx,node *x,LL cnt,LL p){ if(idx<0) return {p,x->sum}; if(x->l->cnt<cnt){ pil q=serch(idx-1,x->r,cnt-x->l->cnt,(p|(1LL<<idx))); q.se+=x->l->sum; return q; } return serch(idx-1,x->l,cnt,p); } LL read(node *RX){ pil p=serch(29,RX,RX->cnt/2,0); return (RX->cnt/2)*p.fi-p.se+(RX->sum-p.se)-(RX->cnt-RX->cnt/2)*p.fi; } int main(){ LL i,x; char a[5],b[5]; scanf("%lld %lld",&k,&n); for(i=1;i<=n;i++){ scanf("%s %lld %s %lld",a,&arr[m].fi,b,&arr[m].se); if(a[0]==b[0]){ aa+=abs(arr[m].fi-arr[m].se); continue; } m++; aa++; } sort(arr,arr+m,[&](const pil x,const pil y){ return x.fi+x.se<y.fi+y.se; }); R1=new node(0,0,NULL,NULL);R1->l=R1->r=R1; R2=new node(0,0,NULL,NULL);R2->l=R2->r=R2; for(i=0;i<m;i++){ R2=R2->update(29,arr[i].fi,1); R2=R2->update(29,arr[i].se,1); } ans=read(R2); if(k==1) return !printf("%lld\n",aa+ans); for(i=0;i<m;i++){ R1=R1->update(29,arr[i].fi,1); R1=R1->update(29,arr[i].se,1); R2=R2->update(29,arr[i].fi,-1); R2=R2->update(29,arr[i].se,-1); x=read(R1)+read(R2); ans=min(ans,x); } printf("%lld\n",aa+ans); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

bridge.cpp: In function 'int main()':
bridge.cpp:39:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld %lld",&k,&n);
                          ^
bridge.cpp:41:53: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s %lld %s %lld",a,&arr[m].fi,b,&arr[m].se);
                                                     ^
#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...