701B.md (1885B)
1 Source: https://codeforces.com/problemset/problem/701/B 2 3 B. Cells Not Under Attack 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 Vasya has the square chessboard of size *n* × *n* and *m* rooks. Initially the chessboard is empty. Vasya will consequently put the rooks on the board one after another. 22 23 The cell of the field is under rook's attack, if there is at least one rook located in the same row or in the same column with this cell. If there is a rook located in the cell, this cell is also under attack. 24 25 You are given the positions of the board where Vasya will put rooks. For each rook you have to determine the number of cells which are not under attack after Vasya puts it on the board. 26 27 Input 28 29 The first line of the input contains two integers *n* and *m* (1 ≤ *n* ≤ 100 000, 1 ≤ *m* ≤ *min*(100 000, *n*2)) — the size of the board and the number of rooks. 30 31 Each of the next *m* lines contains integers *x**i* and *y**i* (1 ≤ *x**i*, *y**i* ≤ *n*) — the number of the row and the number of the column where Vasya will put the *i*-th rook. Vasya puts rooks on the board in the order they appear in the input. It is guaranteed that any cell will contain no more than one rook. 32 33 Output 34 35 Print *m* integer, the *i*-th of them should be equal to the number of cells that are not under attack after first *i* rooks are put. 36 37 Examples 38 39 Input 40 41 ``` 42 3 3 43 1 1 44 3 1 45 2 2 46 ``` 47 48 Output 49 50 ``` 51 4 2 0 52 ``` 53 54 Input 55 56 ``` 57 5 2 58 1 5 59 5 1 60 ``` 61 62 Output 63 64 ``` 65 16 9 66 ``` 67 68 Input 69 70 ``` 71 100000 1 72 300 400 73 ``` 74 75 Output 76 77 ``` 78 9999800001 79 ``` 80 81 Note 82 83 On the picture below show the state of the board after put each of the three rooks. The cells which painted with grey color is not under the attack. 84 85 