POJ 3416 Crossing
来源:互联网 发布:软件服务外包专业 编辑:程序博客网 时间:2024/06/06 03:50
Description
Wintokk has collected a huge amount of coins at THU. One day he had all his coins fallen on to the ground. Unfortunately, WangDong came by and decided to rob Wintokk of the coins.
They agreed to distribute the coins according to the following rules:
Consider the ground as a plane. Wintokk draws a horizontal line on the plane and then WangDong draws a vertical one so that the plane is divided into 4 parts, as shown below.
Wintokk will save the coins in I and III while those fit in II and IV will be taken away by the robber WangDong.
For fixed locations of the coins owned by Wintokk, they drew several pairs of lines. For each pair, Wintokk wants to know the difference between the number of the saved coins and that of the lost coins.
It's guaranteed that all the coins will lie on neither of the lines drew by that two guys.
Input
The first line contains an integer T, indicating the number of test cases. Then T blocks of test cases follow. For each case, the first line contains two integers N and M, where N is the number of coins on the ground and M indicates how many times they are going to draw the lines. The 2nd to (N+1)-th lines contain the co-ordinates of the coins and the last M lines consist of the M pairs integers (x, y) which means that the two splitting lines intersect at point (x, y).
(N,M ≤ 50000, 0 ≤x,y ≤ 500000)
Output
For each query, output a non-negative integer, the difference described above. Output a blank line between cases.
Sample Input
210 329 2217 1418 233 156 2830 274 126 78 011 212 255 1019 2410 528 182 296 513 1220 2715 2611 923 2510 022 2416 3014 317 218 17 4
Sample Output
64422444
树状数组
#include<stack>#include<cmath>#include<queue>#include<vector>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;typedef int ll;const ll maxn=500005;const ll low(ll x) {return x&-x;}ll T,n,m,f[maxn];vector<int> p[maxn];struct point{int x,y,flag,id,ans;void read(int u,int v){ scanf("%d%d",&x,&y); x++; y++; flag=u;ans=0;if (u) id=v; else id=0;}bool operator <(const point &a)const{if (x==a.x) return y<a.y;else return x<a.x;}}a[maxn];bool cmp(const point&a,const point &b){return a.id < b.id;}void insert(int x){for (int i=x;i<maxn;i+=low(i)) f[i]++;}int get(int x){int tot=0;for (int i=x;i;i-=low(i)) tot+=f[i];return tot;}int main(){scanf("%d",&T);while (T--){scanf("%d%d",&n,&m);for (int i=1;i<=n;i++) a[i].read(0,0);for (int i=n+1;i<=n+m;i++) a[i].read(1,i-n);sort(a+1,a+n+m+1);memset(f,0,sizeof(f));for (int i=1;i<=n+m;i++){if (a[i].flag) a[i].ans=get(a[i].y);else insert(a[i].y);}memset(f,0,sizeof(f));for (int i=n+m;i;i--){if (a[i].flag) a[i].ans+=get(maxn-1)-get(a[i].y);else insert(a[i].y);}sort(a+1,a+n+m+1,cmp);for (int i=n+1;i<=n+m;i++){printf("%d\n",abs(2*a[i].ans-n));}if (T) printf("\n");}return 0;}
- POJ 3416 Crossing
- POJ 3416 Crossing
- POJ 3416 Crossing(树状数组)
- [树状数组] poj 3416 Crossing
- POJ 3416 Crossing(树状数组)
- POJ 3416 Crossing --离线+树状数组
- POJ-3416-Crossing-(树状数组)
- POJ-3416 Crossing (树状数组 离线处理)
- poj 1718 River Crossing
- poj 1700 Crossing River
- Poj 1700 Crossing River
- POJ 1700 Crossing River
- [poj] 1700 Crossing River
- POJ 1700 Crossing River
- poj 1700 Crossing River
- POJ-1700-Crossing River
- poj-1700 Crossing River
- POJ 1700 Crossing River
- Fence Repair
- HDU2715 Herd Sums
- veth pair
- [LeetCode] Reverse Nodes in k-Group
- Linux下如何避免僵尸进程的产生
- POJ 3416 Crossing
- 线性表的相关基础概念
- jquery基本常用函数
- 横版动作游戏
- c++ 11 类成员初始化
- POJ 2231 Moo Volume
- 现存的时间可视化方法
- !HDU 4334 集合各出一数和为0是否存在-思维、卡时间-(指针的妙用)
- 2015 Multi-University Training Contest 4(hdu 5327 - hdu 5338)