Bombing
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others) Total Submission(s): 3492 Accepted Submission(s): 1323
Problem Description
It’s a cruel war which killed millions of people and ruined series of cities. In order to stop it, let’s bomb the opponent’s base. It seems not to be a hard work in circumstances of street battles, however, you’ll be encountered a much more difficult instance: recounting exploits of the military. In the bombing action, the commander will dispatch a group of bombers with weapons having the huge destructive power to destroy all the targets in a line. Thanks to the outstanding work of our spy, the positions of all opponents’ bases had been detected and marked on the map, consequently, the bombing plan will be sent to you. Specifically, the map is expressed as a 2D-plane with some positions of enemy’s bases marked on. The bombers are dispatched orderly and each of them will bomb a vertical or horizontal line on the map. Then your commanded wants you to report that how many bases will be destroyed by each bomber. Notice that a ruined base will not be taken into account when calculating the exploits of later bombers.
Input
Multiple test cases and each test cases starts with two non-negative integer N (N<=100,000) and M (M<=100,000) denoting the number of target bases and the number of scheduled bombers respectively. In the following N line, there is a pair of integers x and y separated by single space indicating the coordinate of position of each opponent’s base. The following M lines describe the bombers, each of them contains two integers c and d where c is 0 or 1 and d is an integer with absolute value no more than 109, if c = 0, then this bomber will bomb the line x = d, otherwise y = d. The input will end when N = M = 0 and the number of test cases is no more than 50.
Output
For each test case, output M lines, the ith line contains a single integer denoting the number of bases that were destroyed by the corresponding bomber in the input. Output a blank line after each test case.
Sample Input
3 2
1 2
1 3
2 3
0 1
1 3
0 0
Sample Output
2
1
Source
题意:输入 n,m
接着 n个点的 横纵坐标
m个询问(a,b) a为0代表 输出 横坐标为b的点的个数 并删除扫描过的点
a为1代表 输出 纵坐标为b的点的个数 并删除 扫描过的点
解法:map标记 set离散 有重点 用multiset
STL大法好 涨姿势
注意 格式 PE GG;
#include<bits/stdc++.h> using namespace std; int n,m; int a,b; map<int,multiset<int> >mp1; map<int,multiset<int> >mp2; int main() { while(scanf("%d%d",&n,&m)!=EOF) { if(n==0&&m==0) break; mp1.clear(); mp2.clear(); for(int i=1; i<=n; i++) { scanf("%d %d",&a,&b); mp1[a].insert(b); mp2[b].insert(a); } for(int i=1; i<=m; i++) { scanf("%d%d",&a,&b); if(a==0) { printf("%d\n",mp1[b].size()); for(multiset<int>::iterator it=mp1[b].begin(); it!=mp1[b].end(); it++) mp2[*it].erase(b); mp1[b].clear(); } else { printf("%d\n",mp2[b].size()); for(multiset<int>::iterator it=mp2[b].begin(); it!=mp2[b].end(); it++) mp1[*it].erase(b); mp2[b].clear(); } } printf("\n"); } return 0; }