제출 #140112

#제출 시각아이디문제언어결과실행 시간메모리
140112mohammedehab2002Cake 3 (JOI19_cake3)C++11
0 / 100
3 ms504 KiB
#include <iostream> #include <algorithm> using namespace std; #define sz 30000000 pair<long long,int> tree[sz]; int n,m,lc[sz],rc[sz],root[200005],cn; long long ans; pair<int,int> arr[200005]; void update(int node,int node2,int st,int en,int idx) { tree[node2]=tree[node]; tree[node2].first+=idx; tree[node2].second++; if (st!=en) { if (!lc[node]) lc[node]=++cn; if (!rc[node]) rc[node]=++cn; int mid=(st+en)/2; if (st<=idx && idx<=mid) { lc[node2]=++cn; rc[node2]=rc[node]; update(lc[node],lc[node2],st,mid,idx); } else { rc[node2]=++cn; lc[node2]=lc[node]; update(rc[node],rc[node2],mid+1,en,idx); } } } long long get(int node,int node2,int st,int en,int k) { if (st==en) return 1LL*k*st; if (!lc[node]) lc[node]=++cn; if (!rc[node]) rc[node]=++cn; if (!lc[node2]) lc[node2]=++cn; if (!rc[node2]) rc[node2]=++cn; int mid=(st+en)/2; if (tree[rc[node2]].second-tree[rc[node]].second>=k) return get(rc[node],rc[node2],mid+1,en,k); k-=tree[rc[node2]].second-tree[rc[node]].second; return tree[rc[node2]].first-tree[rc[node]].first+get(lc[node],lc[node2],st,mid,k); } long long query(int l,int r) { return get(root[l],root[r-1],1,1e9,m-2)+arr[l].second+arr[r].second-2*arr[r].first+2*arr[l].first; } void solve(int l,int r,int optl,int optr) { if (r<l) return; int opt=optl,mid=(l+r)/2; for (int i=optl+1;i<=min(mid-m+1,optr);i++) { if (query(i,mid)>query(opt,mid)) opt=i; } ans=max(ans,query(opt,mid)); solve(l,mid-1,optl,opt); solve(mid+1,r,opt,optr); } int main() { scanf("%d%d",&n,&m); for (int i=1;i<=n;i++) scanf("%d%d",&arr[i].second,&arr[i].first); sort(arr+1,arr+n+1); for (int i=1;i<=n;i++) { root[i]=++cn; update(root[i-1],root[i],1,1e9,arr[i].second); } //solve(m,n,1,n-m+1); for (int i=1;i<=n-m+1;i++) { for (int j=i+m-1;j<=n;j++) ans=max(ans,query(i,j)); } printf("%lld",ans); }

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

cake3.cpp: In function 'int main()':
cake3.cpp:73:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&m);
  ~~~~~^~~~~~~~~~~~~~
cake3.cpp:75:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&arr[i].second,&arr[i].first);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...