HDU 4022 STL

 1 // 使用map<int,multiset<int> > 实现一对多,因为会有重点,所以用multimap
 2 
 3 
 4 #include<iostream>
 5 
 6 #include<cstdio>
 7 #include<map>
 8 #include<set>
 9 using namespace std;
10 
11 map<int,multiset<int> > cnt_x,cnt_y;
12 
13 int main(){
14     int n,m;
15     while(scanf("%d%d",&n,&m),n+m){
16         cnt_x.clear();
17         cnt_y.clear();
18         for(int i=0;i<n;i++){
19             int x,y;
20             scanf("%d%d",&x,&y);
21             cnt_x[x].insert(y);
22             cnt_y[y].insert(x);
23         }
24         for(int i=0;i<m;i++){
25             int c,d;
26             scanf("%d%d",&c,&d);
27             multiset<int>::iterator it;    
28             if(c){
29                 printf("%d
",cnt_y[d].size());        
30                 for(it=cnt_y[d].begin();it!=cnt_y[d].end();it++){
31                     cnt_x[*it].erase(d);
32                 }
33                 cnt_y[d].clear();
34             }
35             else{
36                 printf("%d
",cnt_x[d].size());
37                 for(it=cnt_x[d].begin();it!=cnt_x[d].end();it++){
38                     cnt_y[*it].erase(d);
39                 }
40                 cnt_x[d].clear();
41             }
42         }
43         puts("");
44     }
45 }
原文地址:https://www.cnblogs.com/Stomach-ache/p/3703204.html