Originally, I wanted to open two counting arrays to store the number of each element in the row column ..
However, the number of data reaches 10 ^ 9, but the number of data is only 10 ^ 5. Although Discretization can be considered... but I want to try map first. After all, discretization is annoying ~
The usage of multimap is a little different from that of map. However, if we simply use functions in STL, there is no difficulty.
I heard that <STL source code analysis> good... but not suitable for beginners ~ ==== Master classic ..
My wa error is too difficult to find ....
I want to use arrays at the beginning to take the absolute value of D in c d. I'm also drunk.
There is another error... you will see it later when you comment on the code.
After the col [X] and row [x] are output, they are reset to 0. This is a fatal error = _ = because my if condition is> = 0. Then, if you ask again next time it will cause repeated calculation of vertices in the row or column ..
This will cause subsequent errors.
1 # include <iostream> 2 # include <map> 3 using namespace STD; 4 5 multimap <int, int> rowmp; 6 multimap <int, int> colmp; 7 Map <int, int> row; 8 Map <int, int> Col; 9 10 int main () 11 {12 INT n, m, OP, X, Y; 13 while (~ Scanf ("% d", & N, & M) 14 {15 if (! N &&! M) 16 break; 17 row. clear (); 18 rowmp. clear (); 19 Col. clear (); 20 colmp. clear (); 21 While (n --) 22 {23 scanf ("% d", & X, & Y); 24 Col [x] ++; 25 row [y] ++; 26 colmp. insert (pair <int, int> (x, y); 27 rowmp. insert (pair <int, int> (Y, x); 28} 29 multimap <int, int >:: iterator rowit; 30 multimap <int, int> :: iterator coprocessor; 31 While (M --) 32 {33 scanf ("% d", & OP, & X); 34 if (OP) // y = D clear row 35 {36 IF (row [x]> = 0) 37 {38 printf ("% d \ n", row [x]); 39 // row [x] = 0; 40 row [x] =-1; 41 rowit = rowmp. find (x); 42 int num = rowmp. count (x); 43 while (Num --) 44 {45 Col [rowit-> second] --; 46 rowit ++; 47} 48} 49 else50 {51 printf ("0 \ n "); 52} 53} 54 else // X = D clear column 55 {56 If (COL [x]> = 0) 57 {58 printf ("% d \ n ", col [x]); 59 // Col [x] = 0; 60 Col [x] =-1; 61 coprocessor = colmp. find (x); 62 int num = colmp. count (x); 63 while (Num --) 64 {65 row [coprocessor-> second] --; 66 coprocessor ++; 67} 68} 69 else70 {71 printf ("0 \ n"); 72} 73} 74} 75 printf ("\ n"); 76} 77 return 0; 78}
View code
I will learn how to use quicksort + binary.
Today:
I am an easy-to-understand person.
HDU -- 4022 -- multimap <did not learn well when someone else used the Quick Sort + binary query>