bzoj 1288: Neighbours
Description
Input
Output
离散化后用排序+树状数组统计一下
#include<bits/stdc++.h>
typedef long long i64;
const int N=5e5+;
char buf[],*ptr=buf+;
int G(){
if(ptr-buf==)fread(ptr=buf,,,stdin);
return *ptr++;
}
int _(){
int x=;
if(ptr-buf<){
while(*ptr<)++ptr;
while(*ptr>)x=x*+*ptr++-;
}else{
int c=G();
while(c<)c=G();
while(c>)x=x*+c-,c=G();
}
return x;
}
i64 a0,a1,a2,a3,a4;
int xm,ym,n;
int xs[N],ys[N],xp,yp;
int xw[N][],yw[N][],f[N],g[N];
struct pos{
int x,y;
}ps[N],ps2[N],qs[N],qs2[N];
bool cmpx(pos a,pos b){
return a.x<b.x||a.x==b.x&&a.y<b.y;
}
bool cmpy(pos a,pos b){
return a.y<b.y||a.y==b.y&&a.x<b.x;
}
void inc(int*f,int w){
for(++w;w<=n;w+=w&-w)++f[w];
}
int sum(int*f,int w){
int s=;
for(++w;w;w-=w&-w)s+=f[w];
return s;
}
int main(){
xm=_()+,ym=_()+,n=_();
for(int i=;i<n;++i){
ps[i].x=xs[i]=_();
ps[i].y=ys[i]=_();
}
std::sort(xs,xs+n);
xp=std::unique(xs,xs+n)-xs;
std::sort(ys,ys+n);
yp=std::unique(ys,ys+n)-ys;
a0=i64(xm-xp)*(ym-yp);
for(int i=;i<n;++i){
ps[i].x=std::lower_bound(xs,xs+xp,ps[i].x)-xs;
ps[i].y=std::lower_bound(ys,ys+yp,ps[i].y)-ys;
}
memcpy(ps2,ps,n*sizeof(pos));
std::sort(ps,ps+n,cmpx);
for(int i=,j=,p1,p2;i<n;i=j){
int x=ps[i].x;
for(++j;j<n&&ps[j].x==x;++j){
p1=ps[j-].y,p2=ps[j].y;
a2+=ys[p2]-ys[p1]-(p2-p1);
}
p1=yw[x][]=ps[i].y;
p2=yw[x][]=ps[j-].y;
a1+=ys[p1]+ym-ys[p2]-(p1+yp-p2);
}
std::sort(ps2,ps2+n,cmpy);
for(int i=,j=,p1,p2;i<n;i=j){
int y=ps2[i].y;
for(++j;j<n&&ps2[j].y==y;++j){
p1=ps2[j-].x,p2=ps2[j].x;
a2+=xs[p2]-xs[p1]-(p2-p1);
}
p1=ps2[i].x;
p2=ps2[j-].x;
a1+=xs[p1]+xm-xs[p2]-(p1+xp-p2);
qs[y]=(pos){p1,y};
qs2[y]=(pos){p2,y};
}
std::sort(qs,qs+yp,cmpx);
std::sort(qs2,qs2+yp,cmpx);
for(int x=,p=,pp=,i=;x<xp;++x){
for(;p<yp&&qs2[p].x<x;++p)inc(f,qs2[p].y);
for(;pp<yp&&qs[pp].x<x;++pp)inc(g,qs[pp].y);
for(++i;i<n&&ps[i].x==x;++i){
int p1=ps[i-].y,p2=ps[i].y;
a4+=sum(g,p2-)-sum(f,p2-)-(sum(g,p1)-sum(f,p1));
}
a2+=sum(f,yw[x][]-)+p-sum(f,yw[x][]);
}
memset(f,,sizeof(int)*(n+));
for(int x=xp-,p=yp-,t=;x>=;--x){
for(;p>=&&qs[p].x>x;--p)inc(f,qs[p].y),++t;
int s0,s1;
a2+=(s0=sum(f,yw[x][]-))+t-(s1=sum(f,yw[x][]));
}
a3=i64(xm)*ym-n-a0-a1-a2-a4;
printf("%lld %lld %lld %lld %lld\n",a0,a1,a2,a3,a4);
return ;
}
bzoj 1288: Neighbours的更多相关文章
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- 【BZOJ】【1211】【HNOI2004】树的计数
Prufer序列+组合数学 嗯哼~给定每个点的度数!求树的种数!那么很自然的就想到是用prufer序列啦~(不知道prufer序列的……自己再找找资料吧,这里就不放了,可以去做一下BZOJ1005明明 ...
- 【BZOJ】初级水题列表——献给那些想要进军BZOJ的OIers(自用,怕荒废了最后的六月考试月,刷刷水题,水水更健康)
BZOJ初级水题列表——献给那些想要进军BZOJ的OIers 代码长度解释一切! 注:以下代码描述均为C++ RunID User Problem Result Memory Time Code_Le ...
- BZOJ 2127: happiness [最小割]
2127: happiness Time Limit: 51 Sec Memory Limit: 259 MBSubmit: 1815 Solved: 878[Submit][Status][Di ...
- 【CodeVS 1288】埃及分数
http://codevs.cn/problem/1288/ loli秘制面向高一的搜索,好难啊QAQ 我本来想按照分母从大到小搜,因为这样分母从小到大枚举到的第一个可行方案就是最优方案. 但貌似会T ...
- BZOJ 3275: Number
3275: Number Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 874 Solved: 371[Submit][Status][Discus ...
- BZOJ 2879: [Noi2012]美食节
2879: [Noi2012]美食节 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 1834 Solved: 969[Submit][Status] ...
- bzoj 4610 Ceiling Functi
bzoj 4610 Ceiling Functi Description bzoj上的描述有问题 给出\(n\)个长度为\(k\)的数列,将每个数列构成一个二叉搜索树,问有多少颗形态不同的树. Inp ...
- BZOJ 题目整理
bzoj 500题纪念 总结一发题目吧,挑几道题整理一下,(方便拖板子) 1039:每条线段与前一条线段之间的长度的比例和夹角不会因平移.旋转.放缩而改变,所以将每条轨迹改为比例和夹角的序列,复制一份 ...
随机推荐
- git账号申请及创建基线
1.填写注册信息 https://github.com/ 进入官网 填写用户名,邮箱,密码然后点击sign up for github 2.后面不记得了,然后就可以创建项目了 3.填写项目名称及描述, ...
- L207
The leaders of the two countries are planning their summit meeting with a (pledge) to maintain and d ...
- USER 版本与ENG 版本差异
[Description] Android USER 版本与ENG 版本的差异 [Keyword] USER ENG user eng 用户版本 工程版本 差异 [Solution] Goog ...
- sed工具命令
sed是非交互式的编辑器.它不会修改文件,除非使用shell来重定向来保存结果.默认情况下,所有的输出行都被打印到屏幕上. sed编辑器逐行处理文件,并将结果发送到屏幕.具体过程如下:首先sed把当前 ...
- 3.3 shell控制流结构
shell中的控制流包括if then else语句,case语句,for循环,until循环,while循环,break控制,continue控制. 条件测试: 有时判断字符串是否相等或检查文件状态 ...
- 3.1 shell简介、变量、运算符
小知识: ipcs可以查看系统中创建的ipc进程间通信资源,例如信号量.共享内存等.示例如下: 什么是shell? shell是核心程序kernel之外的指令解析器,是一个程序,同时是一种命令语言和程 ...
- TJU Problem 1100 Pi
注: 1. 对于double计算,一定要小心,必要时把与double计算相关的所有都变成double型. 2. for (int i = 0; i < N; i++) //N 不 ...
- 虚拟机lamp环境下,Apache配置虚拟主机
1.在Apache配置文件中开启虚拟主机功能:即:Include etc//extra/httpd-vhosts.conf把前面的#去掉: 2.在extra目录下找到文件httpd-vhosts.co ...
- Linux操作系统网络配置
- 新建Android一个项目-菜鸟篇
①打开Eclipse,单击菜单栏的“File”->把鼠标光标移动到“New”->在弹出的列表框中,如果直接能看到“Android Applicaion Project”选项项,则直接单击此 ...