이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef int ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ll N=1e6+5;
const ld pi=3.14159265359;
const ll INF=(1LL<<30);
#define SQ(i) ((i)*(i))
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(_a) (ll)_a.size()
ll pl=1,pr=0,n,m,x,y,cnt[4*N],rev[N];
long long ans=-INF,sum[4*N];
map<ll,ll> A;
vector<pll> v;
vector<ll> lis;
void insert(ll id,ll l,ll r,ll to,ll d){
if(l==r-1){cnt[id]+=d;sum[id]=cnt[id]*rev[l];return ;}
ll mid=(l+r)/2;
if(to<mid){
insert(id*2,l,mid,to,d);
}else{
insert(id*2+1,mid,r,to,d);
}
cnt[id]=cnt[id*2]+cnt[id*2+1];
sum[id]=sum[id*2]+sum[id*2+1];
}
long long query(ll id,ll l,ll r,ll le){
if(l==r-1){return le*rev[l];}
ll mid=(l+r)/2;
if(le>=cnt[id*2+1]){
return sum[id*2+1]+query(id*2,l,mid,le-cnt[id*2+1]);
}else{
return query(id*2+1,mid,r,le);
}
}
void get_ans(ll l,ll r){
++l;--r;
while(pl>l){insert(1,0,SZ(lis),A[v[--pl].X],1);}
while(pr<r){insert(1,0,SZ(lis),A[v[++pr].X],1);}
while(pl<l){insert(1,0,SZ(lis),A[v[pl++].X],-1);}
while(pr>r){insert(1,0,SZ(lis),A[v[pr--].X],-1);}
}
void solve(ll ql,ll qr,ll al,ll ar){
if(ql>qr)return ;
ll mid=(ql+qr)/2;
long long bans=-INF,bpos=al;
for(int i=min(mid-1,ar);i>=al;i--){
get_ans(i,mid);
long long tans=(cnt[1]<m?-INF:query(1,0,SZ(lis),m)-2*(v[mid].Y-v[i].Y)+v[mid].X+v[i].X);
if(tans>bans){
bpos=i,bans=tans;
}
ans=max(ans,tans);
}
solve(ql,mid-1,al,bpos);
solve(mid+1,qr,bpos,ar);
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
scanf("%d%d",n,m);
m-=2;
REP(i,n)scanf("%d%d",x,y),v.pb(mp(x,y)),lis.pb(x);
sort(lis.begin(),lis.end());
lis.resize(unique(lis.begin(),lis.end())-lis.begin());
REP(i,SZ(lis))rev[i]=lis[i],A[lis[i]]=i;
sort(v.begin(),v.end(),[](pll a,pll b){
return (a.Y!=b.Y?a.Y<b.Y:a.X>b.X);
});
solve(0,n-1,0,n-1);
cout<<ans<<"\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
cake3.cpp: In function 'int main()':
cake3.cpp:77:10: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'll' {aka 'int'} [-Wformat=]
77 | scanf("%d%d",n,m);
| ~^ ~
| | |
| int* ll {aka int}
cake3.cpp:77:12: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'll' {aka 'int'} [-Wformat=]
77 | scanf("%d%d",n,m);
| ~^ ~
| | |
| int* ll {aka int}
cake3.cpp:79:18: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'll' {aka 'int'} [-Wformat=]
79 | REP(i,n)scanf("%d%d",x,y),v.pb(mp(x,y)),lis.pb(x);
| ~^ ~
| | |
| int* ll {aka int}
cake3.cpp:79:20: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'll' {aka 'int'} [-Wformat=]
79 | REP(i,n)scanf("%d%d",x,y),v.pb(mp(x,y)),lis.pb(x);
| ~^ ~
| | |
| int* ll {aka int}
cake3.cpp:77:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
77 | scanf("%d%d",n,m);
| ~~~~~^~~~~~~~~~~~
cake3.cpp:79:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
79 | REP(i,n)scanf("%d%d",x,y),v.pb(mp(x,y)),lis.pb(x);
| ~~~~~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |