ACdream 1127(Base Station-树状数组-2个约束条件)
Base Station
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
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个约束条件)的更多相关文章
- ACdream 1127 Base Station (离线查询+树状数组)
题目链接: http://acdream.info/problem?pid=1127 题目: 移动通信系统中,通信网的建立主要通过基站来完成. 基站可以分为主基站和子基站.子基站和各个移动用户进行连接 ...
- poj 1195:Mobile phones(二维树状数组,矩阵求和)
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 14489 Accepted: 6735 De ...
- POJ 1195 二维树状数组
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 18489 Accepted: 8558 De ...
- POJ 1195 Mobile phones(二维树状数组)
Mobile phones Time Limit: 5000MS Mem ...
- 【POJ1195】【二维树状数组】Mobile phones
Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...
- (简单) POJ 1195 Mobile phones,二维树状数组。
Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...
- poj1159二维树状数组
Suppose that the fourth generation mobile phone base stations in the Tampere area operate as follows ...
- POJ1195(二维树状数组)
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 17176 Accepted: 7920 De ...
- POJ 1195 Mobile phones (二维树状数组)
Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...
随机推荐
- [HTML5] Handle Offscreen Accessibility
Sometime when some component is offscreen, but still get focus when we tab though the page. This can ...
- Android调用第三方App
private List<Map<String, Object>> list = null; private PackageManager mPackageManager; p ...
- Pycharm使用入门
Python安装与Pycharm使用入门 一.安装Python 1.Linux下安装 一般系统默认已安装2.6.6版本,升级成2.7版本, 但 2.6 不能删除,因为系统对它有依赖,epel源里最新的 ...
- CXF WebService中传递复杂对象(List、Map、Array)
转自:https://wenku.baidu.com/view/047ce58ed0d233d4b14e69eb.html 现在开始介绍传递复杂类型的对象.如JavaBean.Array.List.M ...
- 如何让MP4 video视频背景色变成透明?
本文转自:https://www.zhangxinxu.com/wordpress/2019/05/mp4-video-background-transparent/ 亲测,pc端有效,但移动端微信内 ...
- ROS-OPENCV
前言:opencv是一个开源的跨平台计算机视觉库. 前提:1.已下载并编译了相关功能包集,如还未下载,可通过git下载:https://github.com/huchunxu/ros_explorin ...
- HD-ACM算法专攻系列(20)——七夕节
问题描述: AC源码: /**/ #include"iostream" #include"cmath" using namespace std; int mai ...
- [转]C#多线程和线程池
鸣谢原文:http://www.cnblogs.com/wwj1992/p/5976096.html 1.概念 1.0 线程的和进程的关系以及优缺点 windows系统是一个多线程的操作系统.一个程 ...
- Xml实现图片旋转
1. 需求:不使用Java代码,实现旋转图片动画 2.实现:使用Progressbar控件 3. anim/anim_loading.xml <?xml version="1.0&qu ...
- Oracle [sys_connect_by_path] 函数
create table test ( NO NUMBER, VALUE VARCHAR2(100), NAME VARCHAR2(100) ); -------------------------- ...