树状数组+离线操作

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std; int N,M;
int SUM1,SUM2,SUM3,SUM4;
int C[+]; struct Point
{
int x,y,PD,ans,id,BiX,BiY;
} point[*+]; int Lowbit(int x)
{
return x&(-x);
} int GetSum(int End)
{
int sum=;
while(End>)
{
sum=sum+C[End];
End=End-Lowbit(End);
}
return sum;
} void Update(int Start,int num)
{
while(Start<+)
{
C[Start]=C[Start]+num;
Start=Start+Lowbit(Start);
}
} bool cmpPointX(const Point&a,const Point&b)
{
if(a.x==b.x) return a.y<b.y;
return a.x<b.x;
} bool cmpPointY(const Point&a,const Point&b)
{
if(a.y==b.y) return a.x<b.x;
return a.y<b.y;
} bool cmpID(const Point&a,const Point&b)
{
return a.id<b.id;
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int i,j;
scanf("%d%d",&N,&M);
memset(C,,sizeof(C));
for(i=; i<N; i++)
{
scanf("%d%d",&point[i].x,&point[i].y);
point[i].PD=;
point[i].x++;
point[i].y++;
point[i].id=-;
}
for(i=N; i<N+M; i++)
{
scanf("%d%d",&point[i].x,&point[i].y);
point[i].id=i;
point[i].PD=;
point[i].x++;
point[i].y++;
}
int tot=;
sort(point,point+N+M,cmpPointX);
for(i=;i<N+M;i++)
if(point[i].PD)
point[i].BiX=i-tot,tot++;
tot=;
sort(point,point+N+M,cmpPointY);
for(i=;i<N+M;i++)
if(point[i].PD)
point[i].BiY=i-tot,tot++;
for(i=;i<N+M;i++)
{
if(!point[i].PD) Update(point[i].x,);
else
{
SUM2=GetSum(point[i].x);
SUM1=point[i].BiY-SUM2;
SUM3=point[i].BiX-SUM2;
SUM4=N-SUM1-SUM2-SUM3;
point[i].ans=SUM1+SUM3-SUM2-SUM4;
}
}
sort(point,point+N+M,cmpID);
for(i=; i<N+M; i++)
if(point[i].PD)
printf("%d\n",max(point[i].ans,-point[i].ans));
printf("\n");
}
return ;
}

POJ 3416 Crossing的更多相关文章

  1. POJ 3416 Crossing --离线+树状数组

    题意: 给一些平面上的点,然后给一些查询(x,y),即以(x,y)为原点建立坐标系,一个人拿走第I,III象限的点,另一个人拿II,IV象限的,点不会在任何一个查询的坐标轴上,问每次两人的点数差为多少 ...

  2. POJ 1700 Crossing River (贪心)

    Crossing River Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9585 Accepted: 3622 Descri ...

  3. poj 1700 Crossing River 过河问题。贪心

    Crossing River Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9887   Accepted: 3737 De ...

  4. poj 1700 Crossing River C++/Java

    http://poj.org/problem?id=1700 题目大意: 有n个人要过坐船过河,每一个人划船有个时间a[i],每次最多两个人坐一条船过河.且过河时间为两个人中速度慢的,求n个人过河的最 ...

  5. POJ 1700 - Crossing River

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 13982   Accepted: 5349 Description A gr ...

  6. ACM学习历程——POJ 1700 Crossing River(贪心)

    Description A group of N people wishes to go across a river with only one boat, which can at most ca ...

  7. Crossing River POJ过河问题

    A group of N people wishes to go across a river with only one boat, which can at most carry two pers ...

  8. POJ 1797 Heavy Transportation (Dijkstra变形)

    F - Heavy Transportation Time Limit:3000MS     Memory Limit:30000KB     64bit IO Format:%I64d & ...

  9. POJ 1797 Heavy Transportation

    题目链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K T ...

随机推荐

  1. 【git】TurtoiseGit使用手册

    A,创建本地分支 操作:Create Branch ->输入本地分支名 -> OK B,创建本地分支和远程分支的映射 操作: 1,拉取远程分支:Fetch -> 选中Arbitray ...

  2. codefirst mvc Self referencing loop detected for property

    登录时,json序列化用户类时提示错误"Self referencing loop detected for property--",经过5个小时的查找,发现原因可能是,用户类包含 ...

  3. C++知识体系

    基础知识 推荐书目 C++ <C++程序设计>(课程教材即可,简而薄) <STL源码剖析>(对C++进一步深化,也是必备知识) <C++对象模型>(经典中经典,重点 ...

  4. Linux Yum仓库介绍及服务端及客户端配置

    YUM服务器 适合在于内网使用,因为很多包需要国外的网站下载应用包,这样网络很不稳定 下载慢,所有为何不尝试搭建 自己内部的YUM服务器呢 YUM服务器搭建 一 创建yum仓库目录 #mkdir -p ...

  5. sql 函数 DATEADD 使用

    DATEADD ( datepart , number, date ) 在日期中添加或减去指定的时间间隔.   datepart 是规定应向日期的哪一部分返回新值的参数. number 为要增加或减去 ...

  6. python 基础学习4-with语句

    why use With? 有些事情需要事先进行设置,事后进行处理,with语句提供了一个很好的处理方式,例如文件读写处理,有时候可能忘记关闭文件,with可以很好地处理这种现象. with语句用来简 ...

  7. 写Java程序的三十个基本规则【新手必读】

    (1) 类名首字母应该大写.字段.方法以及对象(句柄)的首字母应小写.对于所有标识符,其中包含的所有单词都应紧靠在一起,而且大写中间单词的首字母.例如:  ThisIsAClassName  this ...

  8. hadoop 2.2.0 关于map和reduce的个数的设置

    关于hadoop中的map过程,我的理解是每一个map系统会开启一个JVM进程来处理,map之间相互并行,map函数内串行.这样的想法是否正确? 由于想在hadoop集群上算一个初始输入数据不多,但是 ...

  9. 解题报告8VC Venture Cup 2017 - Elimination Round

    题目链接:http://codeforces.com/contest/755 本蒟蒻做了半天只会做前两道题.. A. PolandBall and Hypothesis 题意:给出n,让你找出一个m, ...

  10. 第七十四节,css边框与背景

    css边框与背景 学习要点: 1.声明边框 2.边框样式 3.圆角边框  本章主要探讨HTML5中CSS边框和背景,通过边框和背景的样式设置,给元素增加更丰富的外观. 声明边框 边框的声明有三个属性设 ...