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 arenot 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 31 13 12 2
output
4 2 0 
input
5 21 55 1
output
16 9 
input
100000 1300 400
output
9999800001 
#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;//注意这里long long int 否则第一组数据都没法过
	 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();
		 new_lie = n -lie.size();
		 total = new_hang * new_lie;
		 cout << total << " ";

	 }

}

  


crossfire 346# B的更多相关文章

  1. 1Z0-053 争议题目解析346

    1Z0-053 争议题目解析346 考试科目:1Z0-053 题库版本:V13.02 题库中原题为: 346.What is the impact of the results of the outp ...

  2. Codeforces Round #346 (Div. 2)---E. New Reform--- 并查集(或连通图)

    Codeforces Round #346 (Div. 2)---E. New Reform E. New Reform time limit per test 1 second memory lim ...

  3. 波音,自动驾驶bug未修复,致346人丧生!5个月内两次坠毁!其中,包括8名中国公民

    一,波音737 MAX再次坠毁 继2018年10月29日,印尼波音737MAX飞机坠入爪哇海,导致178名乘客不幸遇难后,时隔不足5月,上周日,埃塞俄比亚航空公司一架波音737MAX客机在飞往肯尼亚途 ...

  4. Linux下Git命令中文显示乱码的问题解决:274\232\350\256\256\346\200\273\347\273\223

    使用git add添加要提交的文件的时候,如果文件名是中文,会显示形如274\232\350\256\256\346\200\273\347\273\223的乱码. 解决方案:在bash提示符下输入: ...

  5. 【转载】#346 - Polymorphism

    Recall that polymorphism is one of the three core principles of object-oriented programming. Polymor ...

  6. 346. Moving Average from Data Stream

    /* * 346. Moving Average from Data Stream * 2016-7-11 by Mingyang * 这里注意的就是(double) sum / count * su ...

  7. <Design> 359 346

    359. Logger Rate Limiter 用map搭建. class Logger { HashMap<String, Integer> map; /** Initialize y ...

  8. Codeforces Round #346 (Div. 2)E - New Reform(DFS + 好题)

    E. New Reform time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  9. 百度编辑器UEditor ASP.NET示例Demo 分类: ASP.NET 2015-01-12 11:18 346人阅读 评论(0) 收藏

    在百度编辑器示例代码基础上进行了修改,封装成类库,只需简单配置即可使用. 完整demo下载 版权声明:本文为博主原创文章,未经博主允许不得转载.

随机推荐

  1. IOC之Unity

    项目最近用到,查找到比较好的资料,记录哈: Unity 3(一):简介与示例: Unity 3(二):Unity在AOP方面的应用

  2. iOS sizeWithFont 过期 is deprecated

    原文: http://www.cnblogs.com/A--G/p/4819189.html iOS 2.0之后 sizeWithFont就被弃用了: //计算textview 高度 - (float ...

  3. 通常我们使用[NSDate date]方法得到的时间与当前时间不一致,如何解决?

    NSDate *date = [NSDate date];    NSTimeZone *zone = [NSTimeZone systemTimeZone];    NSInteger interv ...

  4. centos 6.x 安装redis

    1.yum 安装 yum install redis 如果提示找不到包的话  可以yum install epel-release   先安装epel第三方库 2.源码安装 https://redis ...

  5. 序列数据挖掘[ZZ]

    一.时间序列数据挖掘 时间序列是数据存在的特殊形式,序列的过去值会影响到将来值,这种影响的大小以及影响的方式可由时间序列中的趋势周期及非平稳等行为来刻画.一般来讲,时间序列数据都具有躁声.不稳定.随机 ...

  6. 数据挖掘相关的10个问题[ZZ]

    NO.1 Data Mining 和统计分析有什么不同? 硬要去区分Data Mining和Statistics的差异其实是没有太大意义的.一般将之定义为Data Mining技术的CART.CHAI ...

  7. 图的遍历(bfs 和dfs)

    BFS的思想: 从一个图的某一个顶点V0出发,首先访问和V0相邻的且未被访问过的顶点V1.V2.……Vn,然后依次访问与V1.V2……Vn相邻且未被访问的顶点.如此继续,找到所要找的顶点或者遍历完整个 ...

  8. android:persistent属性

    application PhoneApp既没有被Broadcast唤醒,也没有被其他service调用,那么是android是通过什么方式来启动PhoneApp,所以就发现了属性android:per ...

  9. Python Tutorial 学习(一)--Whetting Your Appetite

    Whetting Your Appetite [吊你的胃口]... 这里就直接原文奉上了... If you do much work on computers, eventually you fin ...

  10. day11基础代码——函数指针

    // //  main.m //  Demo11 // //  Created by scjy on 15/10/29. //  Copyright © 2015年 lizhipeng. All ri ...