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.
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.
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.
3 3
1 1
3 1
2 2
4 2 0
5 2
1 5
5 1
16 9
100000 1
300 400
9999800001
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.

记一下多少行多少列还是空着的然后乘起来
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
inline LL read()
{
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void write(LL a)
{
if (a<){printf("-");a=-a;}
if (a>=)write(a/);
putchar(a%+'');
}
inline void writeln(LL a){write(a);printf("\n");}
bool mrk1[],mrk2[];
int n,m;
LL col,row;
int main()
{
n=read();m=read();
col=n;row=n;
for (int i=;i<=m;i++)
{
int x=read(),y=read();
if (!mrk1[x])mrk1[x]=,col--;
if (!mrk2[y])mrk2[y]=,row--;
cout<<col*row<<' ';
}
}
cf701B
cf701B Cells Not Under Attack的更多相关文章
- CF 701B Cells Not Under Attack(想法题)
题目链接: 传送门 Cells Not Under Attack time limit per test:2 second memory limit per test:256 megabyte ...
- 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 ...
- Codeforces Round #364 (Div. 2) Cells Not Under Attack
Cells Not Under Attack 题意: 给出n*n的地图,有给你m个坐标,是棋子,一个棋子可以把一行一列都攻击到,在根据下面的图,就可以看出让你求阴影(即没有被攻击)的方块个数 题解: ...
- Cells Not Under Attack
Cells Not Under Attack Vasya has the square chessboard of size n × n and m rooks. Initially the ches ...
- codeforces #364b Cells Not Under Attack
比赛的时候 long long sum=n*n,计算不出1e10长度到数,没有搞掉. 哎,以后要注意这个地方.这个题其实不难: 统计能被攻击到的个数,然后用总的个数减掉就可以了.注意有些地方重复计算, ...
- codeforces 701B B. Cells Not Under Attack(水题)
题目链接: B. Cells Not Under Attack 题意: n*n的棋盘,现在放m个棋子,放一个棋子这一行和这一列就不会under attack了,每次放棋子回答有多少点还可能under ...
- codeforces 701 B. Cells Not Under Attack
B. Cells Not Under Attack time limit per test 2 seconds memory limit per test 256 megabytes input st ...
- CodeForces 701B Cells Not Under Attack
题目链接:http://codeforces.com/problemset/problem/701/B 题目大意: 输入一个数n,m, 生成n*n的矩阵,用户输入m个点的位置,该点会影响该行和该列,每 ...
- Codeforces #364 DIV2
~A题 A. Cards time limit per test 1 second memory limit per test 256 megabytes input standard input ...
随机推荐
- 解密-神秘的 RunLoop
引言 一直以来RunLoop就是个神秘的领域,好多2.3年的开发者都不能准确的表述它的作用,说它神秘,其实RunLoop并没有大家想象中的那么神秘,那么不好理解,本文就带大家好好剖析一下”神秘的Run ...
- Ubuntu常见问题
1. Ubuntu16.04安装完国际版QQ后发现用不了搜狗输入法 sudo mv /usr/bin/ibus-daemon /usr/bin/ibus-daemon.bak
- 使用CSS、JS的几种方法
引用CSS到html网页里的4种方法 1.行内式 在标记的style属性中设定CSS样式,这种方式本质上没有体现出CSS的优势,因此不推荐使用 <div style="widt ...
- windows安装服务
我安装了windows服务的时候监控其他机子的时候,我在调试的时候用的是Account是其他用户是可以正常的,但是安装成服务的时候,老是被拒绝. 后来我将Account改成NetworkService ...
- gir配置
Git配置 1. 用户信息 你个人的用户名称和电子邮件地址,用户名可随意修改,git 用于记录是谁提交了更新,以及更新人的联系方式. $ git config --global user.name & ...
- java编程思想-泛型思维导图
- EXT ajax简单实例
转载:http://www.cnblogs.com/xiepeixing/archive/2012/10/24/2736751.html EXT ajax request是ext中对于ajax请求的实 ...
- (转)dedecms代码详解 很全面
dedecms代码研究(1)开篇dedecms 相信大家一定都知道这个cms 系统,功能比较强大,有比较完善的内容发布,还有内容静态化系统,还有就是它有自己独特的标签系统和模板系统.而模板系统也是其他 ...
- (转)PHP函数set_magic_quotes_runtime()的作用
新手经常遇到的问题是特殊字符提交的时候提示数据库错误,今天给大家介绍一个set_magic_quotes_runtime函数,来帮助我们过滤里面的内容 php函数 set_magic_quotes_r ...
- (转)php5中类的学习
类的结构: 类的内部能可能有三种东西,就是常量(constant),属性(property)和方法(method),功能可以理解成类外部的常量,变量和函数. 复制代码代码如下: <?ph ...