Orz KSS is too greasy.
1. Set and Multiset Basics
Set and Multiset will automatically sort the elements according to specific sorting rules. The difference is that the latter allows repeated elements, but the former does not.
Header files must be included:
# Include <set>
Both set and Multiset are class templates defined in the STD space:
Ii. Set and Multiset Functions
Similar to all associated containers, a balanced binary tree is usually used. In fact, set and Multiset are generally made of red and black trees.
The advantage of Automatic Sorting is that the search for elements has good performance and log time complexity. However, one drawback is:
You cannot directly change the element value. This will disrupt the original order.
To change the element value, delete the old element and insert the new element.
The element can only be accessed through the iterator. From the iterator's point of view, the element value is a constant.
See: http://blog.csdn.net/xiajun07061225/article/details/7459206
Bombing
Time Limit: 4000/2000 MS (Java/others) memory limit: 65768/65768 K (Java/others) total submission (s): 2608 accepted submission (s): 978
Problem descriptionit'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. inputmultiple 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. outputfor 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 input3 2 1 2 1 3 3 0 1 3 0 0 0 sample output2 1 source the 36th ACM/ICPC Asia Regional Shanghai site -- online contest recommendlcy code comes from KSS, I am sorry to post it.
1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <map> 5 # include <set> 6 using namespace STD; 7 int N, m; 8 Map <int, Multiset <int> MP1, MP2; // MP1 uses X as the key value, MP2 uses Y as the key value 9 Multiset <int> :: iterator it; 10 int main () 11 {12 // freopen ("text.txt", "r", stdin); 13 while (~ Scanf ("% d", & N, & M) & N + M) {14 int X, Y, D; 15 mp1.clear (); mp2.clear (); 16 For (INT I = 0; I <n; I ++) {17 scanf ("% d", & X, & Y); 18 MP1 [X]. insert (y); 19 MP2 [Y]. insert (x); 20} 21 for (INT I = 0; I <m; I ++) {22 int CNT = 0; 23 scanf ("% d ", & D, & X); 24 if (D = 0) {25 CNT = MP1 [X]. size (); 26 for (IT = MP1 [X]. begin (); it! = MP1 [X]. end (); It ++) 27 MP2 [* it]. erase (x); 28 MP1 [X]. clear (); 29} 30 else {31 CNT = MP2 [X]. size (); 32 for (IT = MP2 [X]. begin (); it! = MP2 [X]. end (); It ++) 33 MP1 [* it]. erase (x); 34 MP2 [X]. clear (); 35} 36 printf ("% d \ n", CNT); 37} 38 printf ("\ n"); 39} 40 return 0; 41}
HDU 4022 STL Multiset