codeforces #364b Cells Not Under Attack
2 seconds
256 megabytes
standard input
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.
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
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
int n,m;
scanf("%d%d",&n,&m);
long long sum=n;
sum*=sum;
int hang=;
int lie=;
int phang[];
int plie[];
for(int i=;i<=n+;i++){
phang[i]=plie[i]=;
}
long long goji=;
for(int i=;i<m;i++)
{
int tmp1,tmp2;
scanf("%d%d",&tmp1,&tmp2);
if(phang[tmp1]==&&plie[tmp2]==){
goji+=(n+n-);
goji-=lie;
goji-=hang;
}else if(phang[tmp1]!=&&plie[tmp2]==){
goji+=(n-);
goji-=(hang-);
}else if(phang[tmp1]==&&plie[tmp2]!=){
goji+=(n-);
goji-=(lie-);
}
if(phang[tmp1]==){
hang++;
}
if(plie[tmp2]==){
lie++;
}
phang[tmp1]++;
plie[tmp2]++;
printf("%I64d ",sum-goji); } int tmp1,tmp2;
scanf("%d%d",&tmp1,&tmp2);
if(phang[tmp1]==&&plie[tmp2]==){
goji+=((n*)-);
goji-=lie;
goji-=hang;
}else if(phang[tmp1]!=&&plie[tmp2]==){
goji+=(n-);
goji-=(hang-);
}else if(phang[tmp1]==&&plie[tmp2]!=){
goji+=(n-);
goji-=(lie-);
}
if(phang[tmp1]==){
hang++;
}
if(plie[tmp2]==){
lie++;
}
phang[tmp1]++;
plie[tmp2]++;
printf("%I64d\n",sum-goji); return ;
}
codeforces #364b Cells Not Under Attack的更多相关文章
- CodeForces 701B Cells Not Under Attack
题目链接:http://codeforces.com/problemset/problem/701/B 题目大意: 输入一个数n,m, 生成n*n的矩阵,用户输入m个点的位置,该点会影响该行和该列,每 ...
- 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个坐标,是棋子,一个棋子可以把一行一列都攻击到,在根据下面的图,就可以看出让你求阴影(即没有被攻击)的方块个数 题解: ...
- 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 ...
- CF 701B Cells Not Under Attack(想法题)
题目链接: 传送门 Cells Not Under Attack time limit per test:2 second memory limit per test:256 megabyte ...
- Cells Not Under Attack
Cells Not Under Attack Vasya has the square chessboard of size n × n and m rooks. Initially the ches ...
- cf701B Cells Not Under Attack
Vasya has the square chessboard of size n × n and m rooks. Initially the chessboard is empty. Vasya ...
- Codeforces Round #364
http://codeforces.com/contest/701 A - Cards 水 // #pragma comment(linker, "/STACK:102c000000,102 ...
随机推荐
- 【bzoj2142】【礼物】拓展Lucas定理+孙子定理
(上不了p站我要死了,侵权度娘背锅) Description 一年一度的圣诞节快要来到了.每年的圣诞节小E都会收到许多礼物,当然他也会送出许多礼物.不同的人物在小E 心目中的重要性不同,在小E心中分量 ...
- STL之全排列
描述 使用STL中的next_permutation函数输出一个序列的全排列. 部分代码已经给出,请补充完整,提交时请勿包含已经给出的代码. int main() { vector<int> ...
- linux-改变文件属主权限-chown
http://www.cnblogs.com/peida/archive/2012/12/04/2800684.html chown将指定文件的拥有者改为指定的用户或组,用户可以是用户名或者用户ID: ...
- 关于MYsql 多字段排序
SELECT switch_data.* , lan_data.ename FROM switch_data , lan_data WHERE switch_data.address = '佳合丽景' ...
- lync项目总结
概述 9月份,由于公司人事变动,摆在自己面前也有两条路可选择,一是选择lync,二是选择sharepoint,由于之前,部门老大已经让我看了大概一个月的有关lync方面的资料(文档,代码,项目实施等) ...
- 【SQL】查询数据库中某个字段有重复值出现的信息
select name,mobile from [GeneShop].[dbo].[xx_member] where mobile in ( SELECT mobile FROM [GeneShop] ...
- 通过案例对SparkStreaming透彻理解三板斧之二
本节课主要从以下二个方面来解密SparkStreaming: 一.解密SparkStreaming运行机制 二.解密SparkStreaming架构 SparkStreaming运行时更像SparkC ...
- 第五章:关于ESearch的应用
ElasticSearch是一个开源的分布式搜索引擎,具备高可靠性,支持非常多的企业级搜索用例. 我在这里做一下简单介绍和整理: 首先.ES搜索引擎给予java开放使用之前必须安装java环境,使用j ...
- python连接mysql并插入数据(自用)
#coding=utf-8 import MySQLdb db = MySQLdb.connect("IP","用户名","密码",&quo ...
- iOS 调用第三方地图进行导航
//支持的地图 { _model = model; //支持的地图 NSMutableArray *maps = [NSMutableArray array]; //苹果原生地图-苹果原生地图方法和其 ...