B. Cells Not Under Attack
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

题意:n*n的棋盘  m个rook(车 象棋中的ju)  给你m的车的坐标 车所在的行列不能摆放棋子

每摆放一个车 输出还能摆放其他旗子的位置的数量  具体看样例

题解:每次增加一个车 都更新不能摆放棋子的行列的个数 ro,cl

注意行列的交叉点会重复计算 记录每次的结果为ans=n*n-(ro+cl)*n+ro*cl;

 //code  by drizzle
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#define ll __int64
#define PI acos(-1.0)
#define mod 1000000007
using namespace std;
ll n,m;
ll h[];
ll l[];
ll cl,ro;
ll x,y;
ll ans[];
int main()
{
cl=;
ro=;
scanf("%I64d %I64d",&n,&m);
memset(l,,sizeof(l));
memset(h,,sizeof(h));
for(int i=;i<=m;i++)
{
scanf("%I64d %I64d",&x,&y);
if(h[x]==)
{
h[x]=;
ro++;
}
if(l[y]==)
{
l[y]=;
cl++;
}
ans[i]=n*n-(ro+cl)*n+ro*cl;
}
printf("%I64d",ans[]);
for(int i=;i<=m;i++)
printf(" %I64d",ans[i]);
return ;
}

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

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

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

  2. Codeforces Round #364 (Div. 2)

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

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

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

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

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

  5. Codeforces Round #364 (Div. 2) C 二分处理+求区间不同字符的个数 尺取法

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

  6. 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 ...

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

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

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

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

  9. 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 ...

随机推荐

  1. OO第四单元总结

    单元架构设计 本单元OO作业主要涉及两个过程,即先根据输入的elements数组建立UML存储模型,而后基于这个模型实现一系列查询判断功能.汲取上单元的经验,建模过程中模型数据容器的选择依据要求实现的 ...

  2. Andrew NG 自动化所演讲(20140707):DeepLearning Overview and Trends

    出处 以下内容转载于 网友 Fiona Duan,感谢作者分享 (原作的图片显示有问题,所以我从别处找了一些附上,小伙伴们可以看看).最近越来越觉得人工智能,深度学习是一个很好的发展方向,应该也是未来 ...

  3. Bootstrap HTML编码规范

    语法 1.用两个空格来代替制表符(Tab)--这是唯一能保证在所有的环境下获得一致展现的方法. 2.嵌套元素应当缩进一次(即两个空格). 3.对于属性的定义,属性值确保全部都用双引(避免使用单引号). ...

  4. 2018.11.3 Nescafe18 T1 七夕祭

    题目 背景 七夕节因牛郎织女的传说而被扣上了「情人节」的帽子.于是 TYVJ 今年举办了一次线下七夕祭.Vani 同学今年成功邀请到了 cl 同学陪他来共度七夕,于是他们决定去 TYVJ七夕祭游玩. ...

  5. position的 relative+absolute实现固定标签在窗口的某个位置

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. 【前端_js】Chrome禁止缓存的方法

    在前端开发中,浏览器缓存使得我们改了代码后页面不变,得经常手动清理缓存. 1.按如下操作即可禁用浏览器缓存, 这种方法基本能够做到完全禁止缓存,然而缺点是必须要将开发模式一直打开,占用屏幕空间.而且, ...

  7. 如何修改iframe内的页面的元素的样式。。。。

    方法一: 直接通过设置backgroundColor的颜色即可:<!DOCTYPE html><html><head><script>function ...

  8. Python基础闯关失败总结

    对列表进行创建切片增删改查 对列表进行创建 L1 = []  # 定义L1 为一个空列表 List() #创建List 空列表 对列表进行查询 L2 = ['a','b','c','d','a','e ...

  9. Azure继续降价云 价格战就此终结?

    [TechTarget中国原创] 刚刚跨入2016年,就听到了云降价这样一个消息,但是我们却不要期望降价之风如去年一样呼呼不绝. 微软公司在本周宣称,他们将在下个月对其D系列虚拟机实施高达17%的降价 ...

  10. CSS中behavior属性语法简介

    本文和大家重点讨论一下CSS中behavior属性语法的使用,在进行CSS网页布局的时候,我们经遇到刷新要保留表单里内容的时候,习惯的做法使用cookie,但是那样做实在是很麻烦,CSS中的behav ...