cf701B Cells Not Under Attack

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.

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.

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.

Input

The first line of the input contains two integers n and m (1 ≤ n ≤ 100 000, 1 ≤ m ≤ min(100 000, n2)) — the size of the board and the number of rooks.

Each of the next m lines contains integers xi and yi (1 ≤ xi, yi ≤ 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.

Output

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.

Examples
input
3 3
1 1
3 1
2 2
output
4 2 0 
input
5 2
1 5
5 1
output
16 9 
input
100000 1
300 400
output
9999800001 
Note

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.

 记一下多少行多少列还是空着的然后乘起来

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<cstring>
 4 #include<cstdlib>
 5 #include<algorithm>
 6 #include<cmath>
 7 #include<queue>
 8 #include<deque>
 9 #include<set>
10 #include<map>
11 #include<ctime>
12 #define LL long long
13 #define inf 0x7ffffff
14 #define pa pair<int,int>
15 #define pi 3.1415926535897932384626433832795028841971
16 using namespace std;
17 inline LL read()
18 {
19     LL x=0,f=1;char ch=getchar();
20     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
21     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
22     return x*f;
23 }
24 inline void write(LL a)
25 {
26     if (a<0){printf("-");a=-a;}
27     if (a>=10)write(a/10);
28     putchar(a%10+'0');
29 }
30 inline void writeln(LL a){write(a);printf("
");}
31 bool mrk1[100010],mrk2[100010];
32 int n,m;
33 LL col,row;
34 int main()
35 {
36     n=read();m=read();
37     col=n;row=n;
38     for (int i=1;i<=m;i++)
39     {
40         int x=read(),y=read();
41         if (!mrk1[x])mrk1[x]=1,col--;
42         if (!mrk2[y])mrk2[y]=1,row--;
43         cout<<col*row<<' ';
44     }
45 }
cf701B
——by zhber,转载请注明来源
原文地址:https://www.cnblogs.com/zhber/p/5698439.html