Description

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 

我们把x,y记录一下,根据情况去行还是去列
#include<bits/stdc++.h>
using namespace std;
long long n,m;
long long sum;
long long px[100005],py[100005];
long long ans[100005];
int main()
{
long long x,y;
int pos;
cin>>n>>m;
pos=n;
sum=n*n;
for(int i=1; i<=m; i++)
{
cin>>x>>y;
if(px[x]==0&&py[y]==0)
{
n--;
pos--;
// ans[i]=n*pos;
// cout<<"A"<<endl;
}
else if(px[x]&&py[y]==0)
{
pos--;
// ans[i]=n*pos;
}
else if(px[x]==0&&py[y])
{
n--;
// ans[i]=n*pos;
}
px[x]=1;
py[y]=1;
cout<<pos*n<<endl;
}
return 0;
}

  

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.

Codeforces Round #364 (Div. 2) B的更多相关文章

  1. Codeforces Round #364 (Div. 2)

    这场是午夜场,发现学长们都睡了,改主意不打了,第二天起来打的virtual contest. A题 http://codeforces.com/problemset/problem/701/A 巨水无 ...

  2. Codeforces Round #364 (Div.2) D:As Fast As Possible(模拟+推公式)

    题目链接:http://codeforces.com/contest/701/problem/D 题意: 给出n个学生和能载k个学生的车,速度分别为v1,v2,需要走一段旅程长为l,每个学生只能搭一次 ...

  3. Codeforces Round #364 (Div.2) C:They Are Everywhere(双指针/尺取法)

    题目链接: http://codeforces.com/contest/701/problem/C 题意: 给出一个长度为n的字符串,要我们找出最小的子字符串包含所有的不同字符. 分析: 1.尺取法, ...

  4. 树形dp Codeforces Round #364 (Div. 1)B

    http://codeforces.com/problemset/problem/700/B 题目大意:给你一棵树,给你k个树上的点对.找到k/2个点对,使它在树上的距离最远.问,最大距离是多少? 思 ...

  5. Codeforces Round #364 (Div. 2) B. Cells Not Under Attack

    B. Cells Not Under Attack time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  6. Codeforces Round #364 (Div. 2) Cells Not Under Attack

    Cells Not Under Attack 题意: 给出n*n的地图,有给你m个坐标,是棋子,一个棋子可以把一行一列都攻击到,在根据下面的图,就可以看出让你求阴影(即没有被攻击)的方块个数 题解: ...

  7. Codeforces Round #364 (Div. 2) Cards

    Cards 题意: 给你n个牌,n是偶数,要你把这些牌分给n/2个人,并且让每个人的牌加起来相等. 题解: 这题我做的时候,最先想到的是模拟,之后码了一会,发现有些麻烦,就想别的方法.之后发现只要把它 ...

  8. Codeforces Round #364 (Div. 2)->A. Cards

    A. Cards time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...

  9. Codeforces Round #364 (Div. 2) E. Connecting Universities

    E. Connecting Universities time limit per test 3 seconds memory limit per test 256 megabytes input s ...

  10. Codeforces Round #364 (Div. 2) C.They Are Everywhere

    C. They Are Everywhere time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

随机推荐

  1. [转]CSS3 Filter的十种特效

    最近到处看到有人在说CSS3的filter一直没有时间自己去测试这效果.今天终于抽出时间学习这个CSS3的Filter.不整不知道呀,一整才让我感到吃惊,太强大了.大家先来看个效果吧: 我想光看上面的 ...

  2. tx2在自制载板上无法识别usb以及pcie无法读取数据

    注意使用的系统版本是Jetpack-3.1,其它版本的系统上没有测试过!!! 刷机时替换dtb文件: 将Jetpack刷机包 64_TX2/Linux_for_Tegra_tx2/kernel/dtb ...

  3. Ubuntu14.04如何用root账号登陆系统

    在虚拟机VMWARE中安装完Ubuntu后,只能用新建的普通用户登陆,很不方便做实验:那如何用root用户登陆账号呢? (1)用普通账号登陆,打开终端terminal: (2)在terminal的输入 ...

  4. httpd或Nginx负载均衡tomcat

    实验环境:CentOS7 #两台tomcat的基本配置如下: [root@webapps localhost]#setenforce 0 [root@webapps localhost]#iptabl ...

  5. etcd命令

    etcdctl支持下面列出来的命令,基本上可以分为数据库操作和非数据库操作,可以查看etcdctl README.md来了解更多 ➜ ~ etcdctl -hNAME: etcdctl - A sim ...

  6. javascript之系统对话框

    浏览器通过alert(),confirm()和prompt()方法调用系统对话框,向用户显示信息. alert()接受一个字符串并显示给用户,结果是显示一个对话框,其中包括指定的文本和一个OK(“确定 ...

  7. Java探索之旅(3)——选择与循环

    1.选择结构与输出 ❶Switch语句: Switch表达式必须算出 char,byte,short,int类型数值之一,总是括号括住:Value1----ValueN,对应有相同数据类型且为常量或者 ...

  8. 《精通Spring4.X企业应用开发实战》读后感第七章(创建增强类)

  9. 10.Redis未授权访问漏洞复现与利用

    一.漏洞简介以及危害: 1.什么是redis未授权访问漏洞: Redis 默认情况下,会绑定在 0.0.0.0:6379,如果没有进行采用相关的策略,比如添加防火墙规则避免其他非信任来源 ip 访问等 ...

  10. 5. Python大法之告别脚本小子--各类URL采集器编写

    在i春秋上面,有很多不错的脚本: https://bbs.ichunqiu.com/forum.php?mod=collection&action=view&ctid=137 http ...