树状数组+离线操作

#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. 关于oracle数据库(11)

    事务 事务是最小的工作单元,是对数据库的若干操作,增删查改(要不就都成功,要不就都失败) 在oracle数据库中,事务是默认打开的,其他数据库都需要一条语句来打开事务,默认关闭的 事务的特征 原子性. ...

  2. mysql中文显示问号

    mysql插入中文后显示为?,查到http://blog.csdn.net/chenxingzhen001/article/details/7567812中方法,即 在my.ini配置文件中的[myd ...

  3. Cookie小解2

    Cookie最早用来标识和认证一个用户,其处理分为以下几步: 1.服务端向客户端发送Cookie 2.浏览器将Cookie保存 3.之后每次浏览器服务服务器时都会将Cookie发向服务器端 ----- ...

  4. Voting

    Voting time limit per test 1 second memory limit per test 256 megabytes input standard input output ...

  5. vue 相对其他热门 框架 优点 --- 待续

    react vs  vue 1. 处理动画 vue 更有优势 , 这是由于 React 有大量的检查机制 2.性能更高, 在React中,你需要在每个地方去实现 shouldComponentUpda ...

  6. JavaScript eval() 为什么使用eval()是一个坏主意 什么时候可以使用eval()

    ---------------------------------------------------------------------------------------------------- ...

  7. 折腾一天,终于配置好了,ssl证书,启用了https,用的阿里云ECS服务器

    阿里云ECS服务器配置了ssl证书, httpd-ssl.conf  的配置很重要,网站目录一定要设置正确. 阿里云的虚拟空间,弹性Web,目前好像还不支持ssl证书. 最后要网站强制https,下面 ...

  8. css3 div垂直居中

    css3: #dd{ height: 300px; background: #0000cc; display: -webkit-box; display: flex; display: -webkit ...

  9. WebService第一天

    WebService第一天 [课程安排]: 整体安排:2天: 第一天:webservice入门,JDK规范和实现:jax-ws,相关概念 第二天:CXF框架,和spring的集成开发.Hessian的 ...

  10. JavaScript面向对象基础语法总结

    1.Javascript的 对象(Object): //例子:var car = { , , }; 2.使用构造函数来创建对象. //例子: var Car = function() { ; ; ; ...