Crossfire 346# B

Source: Internet
Author: User

Vasya has the square chessboard of size n x n and m rooks. Initially the chessboard is empty. Vasya would consequently put the rooks on the board one after another.

The cell of the field is under Rook ' s attack, if there are at least one rook located in the same row or in the same column With the 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 would put rooks. For each rook you has to determine the number of cells which is notunder attack after Vasya puts it on the board.

Input

The first line of the input contains the Integers  n  and  m   (1≤ n ≤100 000, 1≤ m min ($, n 2))  -the size of the board and the number of rooks .

Each of the next m lines contains integers xi and yi ( 1≤ x i, yin)-the number of the row and the number of the column where Vasya would put the i-th rook. Vasya puts rooks on the board in the order they appear in the input. It is guaranteed the any cell would contain no more than one rook.

Output

Print m Integer, the i-th of them should is equal to the number of cells that is not under Atta CK after first i rooks is put.

Examplesinput
3 3
1 1
3 1
2 2
Output
Input
5 2
1 5
5 1
Output
Input
100000 1
300 400
Output


#include <stdio.h> #include <iostream> #include <string.h> #include <algorithm> #include < string> #include <math.h> #include <cmath> #include <vector> #include <set>using namespace Std;int Main () {long long int n; long long int m; int a b; Cin >> n >> m; set <long long int> hang; set <long long int> lie;//Note here a long long int otherwise the first set of data can not be a long long int total = N*n; Long long int new_hang; Long long int new_lie; for (int i = 0; i < m; i++) {scanf ("%d%d", &a,&b); Hang.insert (a); Lie.insert (b); New_hang = N-hang.size (); NE W_lie = N-lie.size (); Total = New_hang * New_lie; cout << Total << "";}}

  




Crossfire 346# B

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.