# Code

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>

#define rep(i,st,ed) for (int i=st;i<=ed;++i)
#define drp(i,st,ed) for (int i=st;i>=ed;--i)
#define lb(x) (x&-x)

typedef long double ld;
const int N=2000005;
const ld eps=1e-9;

struct pos {
ld x,y;
} p[N],jiao[N];

struct Q {
ld x;
int y1,y2,xs;
} q[N];

int r[N],id[N],s[N],n,cb,cj,cq;
ld b[N];

bool vis[N];

int x=0,v=1; char ch=getchar();
for (;ch<'0'||ch>'9';v=(ch=='-')?(-1):v,ch=getchar());
for (;ch<='9'&&ch>='0';x=x*10+ch-'0',ch=getchar());
return x*v;
}

for (;x<=cb+5;x+=lb(x)) s[x]+=v;
}

int get(int x) {
int res=0;
for (;x;x-=lb(x)) res+=s[x];
return res;
}

pos inte(pos a,pos b,pos c,pos d) {
ld a1=b.y-a.y,b1=a.x-b.x;
ld c1=a1*a.x+b1*a.y;
ld a2=d.y-c.y,b2=c.x-d.x;
ld c2=a2*c.x+b2*c.y;
ld cross=a1*b2-a2*b1;
if (cross==0) return {-1,-1};
else return {(b2*c1-b1*c2)/cross,(a1*c2-a2*c1)/cross};
}

bool cmp1(int x,int y) {
return p[x+n].y<p[y+n].y;
}

bool cmp2(Q x,Q y) {
if (fabs(x.x-y.x)>eps) return x.x<y.x;
if (x.xs!=y.xs) return x.xs>y.xs;
return false;
}

int main(void) {
freopen("data.in","r",stdin);
rep(i,1,n) id[i]=i;
std:: sort(id+1,id+n+1,cmp1);
rep(i,1,n) r[id[i]]=i;
int cnt=n;
rep(i,1,n) if (!vis[i]) {
cnt--; int x=r[i];
while (x!=i) vis[x]=1,x=r[x];
}
rep(i,1,n) id[i]=i;
rep(i,1,n) rep(j,i,n*2) if (i==r[j]) {
int aj=id[j];
drp(k,j-1,i) {
pos res=inte(p[id[k]],p[id[k]+n],p[aj],p[aj+n]);
jiao[++cj]=(pos) {res.x+res.y,res.x-res.y};
std::swap(r[k],r[k+1]);
id[k+1]=id[k];
} break;
}
rep(i,1,m) {
int x=tx+ty,y=tx-ty;
q[++cq]=(Q) {(ld)x-c,y-c,y+c,1}; b[cq]=y-c;
q[++cq]=(Q) {(ld)x+c,y-c,y+c,-1}; b[cq]=y+c;
}
cb=cq;
rep(i,1,cj) b[++cb]=jiao[i].y;
std:: sort(b+1,b+cb+1);
int tmp=cb; cb=1;
rep(i,2,tmp) if (fabs(b[i]-b[i-1])>eps) b[++cb]=b[i];
rep(i,1,cq) {
q[i].y1=std:: lower_bound(b+1,b+cb+1,q[i].y1)-b;
q[i].y2=std:: lower_bound(b+1,b+cb+1,q[i].y2)-b;
}
rep(i,1,cj) {
int y=std:: lower_bound(b+1,b+cb+1,jiao[i].y)-b;
q[++cq]=(Q) {jiao[i].x,y};
}
std:: sort(q+1,q+cq+1,cmp2);
int wjp=0;
rep(i,1,cq) {
if (q[i].xs) {
} else wjp+=(get(q[i].y1)!=0);
}
int mxs=A*cj+wjp*C;
int mns=A*cnt+B*(cj-cnt)+wjp*C;
if (mxs<mns) std:: swap(mxs,mns);
printf("%d %d\n", mns,mxs);
return 0;
}


©️2019 CSDN 皮肤主题: 技术黑板 设计师: CSDN官方博客