树状数组+离线操作

#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. ring3 hook ZwWriteVirtualMemory

    typedef LONG NTSTATUS;typedef NTSTATUS (NTAPI *PNtZwWriteVirtualMemory) ( IN HANDLE hProcess, IN PVO ...

  2. UIBezierPath与CAShapeLayer结合画扇形

    /*让半径等于期望半径的一半 lineWidth等于期望半径 就可以画圆*/ 可以看出layer的走势是从圆边的中间一半在圆外 一半在圆内 因此让半径等于期望半径的一半 lineWidth等于期望半径 ...

  3. python获取

    def anc():pass print anc.__name__ def timeit(func): def run(*argv): print "this function name i ...

  4. 顺序表(C++实现)

    类实现代码如下: ;//默认的表空间大小 template <class T> class SeqList{ protected: T *data;//存放数组 int maxSize;/ ...

  5. Linux格式化字符串

    > 常用 > 详细 给定的格式FORMAT 控制着输出,解释序列如下: %% 一个文字的 % %a 当前locale 的星期名缩写(例如: 日,代表星期日) %A 当前locale 的星期 ...

  6. 工艺成型及仿真、铸造工艺及仿真ProCAST软件入门认识介绍

    视频源:技术邻 关键词:ProCAST.工艺成型及仿真.铸造工艺及仿真 简介:ProCAST 软件是由美国 USE 公司开发的铸造过程的模拟软件采用基于有限元(FEM)的数值计算和综合求解的方法,对铸 ...

  7. javaWEB总结(13):域对象的属性操作

    前言 本文主要讲解javaweb的四个域对象以及他们的作用范围,后面会有小demo来具体测试. 四个域对象 (1)pageContext:属性的作用范围仅限于当前JSP页面: (2)request:属 ...

  8. The most orzed and orzing man

    The most orzed and orzing man 题目链接:http://acm.xidian.edu.cn/problem.php?id=1184 Sprague-Grundy定理:htt ...

  9. ZUFEOJ 2395 天棋哥哥大战AlphGo

    Description3月15日,人机围棋大战巅峰对决在韩国首尔落下帷幕.五番棋的最后一局中,韩国著名棋手李世乭尽管与人工智能“AlphaGo”缠斗至官子阶段,但在双双进入读秒后最终还是投子认输,以总 ...

  10. laravel5.2/laravel5.3入门指南 Windows 上快速安装并运行 Laravel 5.x

    1 首先要搭建本地服务器环境推荐phpstudy2016及wampServer3.0.6 下载链接可参考 http://www.cnblogs.com/zzcit/p/5823742.html 注意一 ...