Base Station

Time Limit: 20000/10000MS (Java/Others)Memory Limit: 512000/256000KB (Java/Others)

Problem Description

移动通信系统中。通信网的建立主要通过基站来完毕。

基站能够分为主基站和子基站。子基站和各个移动用户进行连接,子基站必须通过主基站来和外界实现通信。主基站能够覆盖到的范围是一个圆形区域,子基站和主基站的距离小于半径r才干被该主基站覆盖到。半径r由主基站的发射功率确定。

某个区域的移动通信网,包括2个主基站和N个子基站。它们的位置都能够相应到一个整数坐标上。假设子基站至少被一个主基站覆盖。则该子基站是激活的。

如今通信公司在调试设备,它们不停地改变主基站的发射功率。当两个主基站的覆盖半径分别为r1和r2时,须要知道有多少个子基站处于非激活状态。

Input

有若干组输入数据。

第一行是四个整数:x1、y1、x2、y2(1<=x1、y1、x2、y2<=10^9),表示两个主基站的坐标是(x1,y1)和(x2,y2)。

第二行是一个整数N(1<=N<=100000),表示有N个子基站。

接下来的N行。每行两个整数x、y(1<=x, y<=10^9)。表示每一个子基站的坐标。

接下来一行包括一个整数M(1<=M<=100000),表示有M个询问。

接下来的M行。每行两个整数r1、r2(1<=r1, r2<=10^9)。表示询问当两个主基站的覆盖半径为r1和r2时。处于非激活状态的子基站数。

Output

对每一个查询,输出答案。

Sample Input

1 10 5 2
5
2 6
1 9
3 8
6 7
4 12
5
1 1
3 2
8 2
2 2
3 2

Sample Output

5
3
0
4
3

Hint

Source

kuangbin

Manager


将基站到2个主站的距离^2表示成二维坐标

则本题的询问表示成半径^2

本题等价于“平面上有n个点,问n-横坐标<r1纵坐标<r2的点数".

用树状数组维护。先依照x从小到大插入,询问y值,得到左下角点数->左上角点数。

接着用容斥。求右上角的点数

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Lson (x<<1)
#define Rson ((x<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define MAXN (100000+10)
#define MAXXi (1000000000)
#define MAXM (100000+10)
long long mul(long long a,long long b){return (a*b)%F;}
long long add(long long a,long long b){return (a+b)%F;}
long long sub(long long a,long long b){return (a-b+(a-b)/F*F+F)%F;}
typedef long long ll;
int n,X1,Y1,X2,Y2,m,tot;
int lowbit(int x){return x&(-x);}
ll sqr(ll x){return x*x;}
ll dis2(ll x1,ll y1,ll x2,ll y2){return sqr(x1-x2)+sqr(y1-y2);}
struct arr_tree
{
int a[MAXN+MAXM*6];
void reset(){ MEM(a) }
void add1(int x)
{
for(;x<=tot;x+=lowbit(x)) a[x]++;
}
int sum(int x)
{
int ans=0;
for(;x>0;x-=lowbit(x)) ans+=a[x];
return ans;
}
}T;
struct node
{
ll x,y; //距离^2
friend bool operator<(node a,node b){return a.x<b.x; }
}a[MAXN*2];
struct comm
{
ll r1,r2; //半径^2
int i;
friend bool operator<(comm a,comm b){return a.r1<b.r1; }
}ask[MAXM*2];
int ans[MAXM*2];
ll y_[MAXN+MAXM*2];
int loc(ll y)
{
return lower_bound(y_+1,y_+1+tot,y)-y_;
}
int main()
{
while (scanf("%d%d%d%d",&X1,&Y1,&X2,&Y2)==4)
{
T.reset();
scanf("%d",&n);
For(i,n)
{
int x,y;
scanf("%d%d",&x,&y);
a[i].x=dis2(x,y,X1,Y1);a[i].y=dis2(x,y,X2,Y2);
y_[i]=a[i].y;
}
sort(a+1,a+1+n);
scanf("%d",&m);
For(i,m)
{
int r1,r2;
scanf("%d%d",&r1,&r2);
ask[i].i=i;ask[i].r1=sqr(r1);ask[i].r2=sqr(r2);
y_[n+i]=ask[i].r2;
}
sort(ask+1,ask+1+m); sort(y_+1,y_+n+m+1);
tot=unique(y_+1,y_+n+m+1)-(y_+1); int j=1;
For(i,m)
{
while(j<=n&&a[j].x<ask[i].r1) T.add1(loc(a[j].y)),j++;
ans[ask[i].i]=j-1-T.sum(loc(ask[i].r2)-1);
}
while(j<=n) T.add1(loc(a[j].y)),j++;
For(i,m) ans[ask[i].i]+=T.sum(loc(ask[i].r2)-1);
For(i,m) printf("%d\n",n-ans[i]);
}
return 0;
}

ACdream 1127(Base Station-树状数组-2个约束条件)的更多相关文章

  1. ACdream 1127 Base Station (离线查询+树状数组)

    题目链接: http://acdream.info/problem?pid=1127 题目: 移动通信系统中,通信网的建立主要通过基站来完成. 基站可以分为主基站和子基站.子基站和各个移动用户进行连接 ...

  2. poj 1195:Mobile phones(二维树状数组,矩阵求和)

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 14489   Accepted: 6735 De ...

  3. POJ 1195 二维树状数组

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 18489   Accepted: 8558 De ...

  4. POJ 1195 Mobile phones(二维树状数组)

                                                                  Mobile phones Time Limit: 5000MS   Mem ...

  5. 【POJ1195】【二维树状数组】Mobile phones

    Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...

  6. (简单) POJ 1195 Mobile phones,二维树状数组。

    Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...

  7. poj1159二维树状数组

    Suppose that the fourth generation mobile phone base stations in the Tampere area operate as follows ...

  8. POJ1195(二维树状数组)

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 17176   Accepted: 7920 De ...

  9. POJ 1195 Mobile phones (二维树状数组)

    Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...

随机推荐

  1. wordpress迁移以及遇到的一些问题[mysql备份导入导出][固定链接404]

    总的问题有两个,一是apache的配置,二是mysql的导出和导入.以及迁移后遇到的一些问题解决过程和方法. A机器为老server.B为新server,A机器使用Appserv,B使用wmap,在配 ...

  2. java中File的delete()方法删除文件失败的原因

    java中File的delete()方法删除文件失败的原因 学习了:http://hujinfan.iteye.com/blog/1266387 的确是忘记关闭了: 引用原文膜拜一下: 一般来说 ja ...

  3. android setCookie 免登录

    CookieSyncManager.createInstance(getActivity()); CookieManager cookieManager = CookieManager.getInst ...

  4. 基于lucene的案例开发:纵横小说分布式採集

    转载请注明出处:http://blog.csdn.net/xiaojimanman/article/details/46812645 http://www.llwjy.com/blogdetail/9 ...

  5. Gzip压缩优化网站

    网站常使用GZIP压缩算法对网页内容进行压缩,然后传给浏览器,以减小数据传输量,提高响应速度.浏览器接收到GZIP压缩数据后会自动解压并正确显示.GZIP加速常用于解决网速慢的瓶颈. 压缩Filter ...

  6. Ubuntu输入su提示认证失败的解决方法

    用su切换,输入密码提示认证失败,这下搞了吧,后来一经查阅原来Ubuntu安装后,root用户默认是被锁定了的,不允许登录,也不允许 su 到 root ,对于桌面用户来说这个可能是为了增强安全性,但 ...

  7. Python学习历程之面对对象浅识

    # ===============================封装====================================# class Bar:# def __init__(se ...

  8. HttpClient连接超时及读取超时

    HttpClient连接超时及读取超时 httpClient在执行具体http请求时候 有一个连接的时间和读取内容的时间: HttpClient连接时间 所谓连接的时候 是HttpClient发送请求 ...

  9. 迭代Iterator的用法

    迭代→遍历: 一个标准化遍历各类容器里面的所有对象的方法类(典型的设计模式) 把访问逻辑从不同类型的集合类中抽象出来,从而避免向客户端暴露集合的内部结构 迭代(Iterator)与枚举(Enumera ...

  10. QT-helloworld-Qt设计师编写

    前言:Qt设计师界面类就是C++类和ui文件的结合,它将这两个文件一起生成了,而不用再逐一添加. 目标:在对话框中显示出“helloworld”字样. 一.新建项目 1.1 选择项目模板 文件→新建文 ...