Codeforces Round #364 (Div. 2) B 标记
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
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 标记的更多相关文章
- Codeforces Round #364 (Div.2) C:They Are Everywhere(双指针/尺取法)
题目链接: http://codeforces.com/contest/701/problem/C 题意: 给出一个长度为n的字符串,要我们找出最小的子字符串包含所有的不同字符. 分析: 1.尺取法, ...
- Codeforces Round #364 (Div. 2)
这场是午夜场,发现学长们都睡了,改主意不打了,第二天起来打的virtual contest. A题 http://codeforces.com/problemset/problem/701/A 巨水无 ...
- Codeforces Round #364 (Div.2) D:As Fast As Possible(模拟+推公式)
题目链接:http://codeforces.com/contest/701/problem/D 题意: 给出n个学生和能载k个学生的车,速度分别为v1,v2,需要走一段旅程长为l,每个学生只能搭一次 ...
- 树形dp Codeforces Round #364 (Div. 1)B
http://codeforces.com/problemset/problem/700/B 题目大意:给你一棵树,给你k个树上的点对.找到k/2个点对,使它在树上的距离最远.问,最大距离是多少? 思 ...
- Codeforces Round #364 (Div. 2) C 二分处理+求区间不同字符的个数 尺取法
C. They Are Everywhere time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- 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 Round #364 (Div. 2) Cards
Cards 题意: 给你n个牌,n是偶数,要你把这些牌分给n/2个人,并且让每个人的牌加起来相等. 题解: 这题我做的时候,最先想到的是模拟,之后码了一会,发现有些麻烦,就想别的方法.之后发现只要把它 ...
- 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 ...
随机推荐
- 牛客小白月赛5 I 区间 (interval) 【前缀和】
链接:https://www.nowcoder.com/acm/contest/135/I 题目描述 Apojacsleam喜欢数组. 他现在有一个n个元素的数组a,而他要对a[L]-a[R]进行M次 ...
- 【C++学习笔记】强大的算法——spfa
spfa的定义 PFA算法的全称是:Shortest Path Faster Algorithm,用于求单源最短路,由西南交通大学段凡丁于1994年发表.当给定的图存在负边时,Dijkstra算法就无 ...
- GVIM——简直美如画,有没有!
"========================================== " Author: wklken " Version: 9.1 " Em ...
- 认识mysql(3)
认识mysql第三篇,发出的内容适合初学者,如果能持续关注我的博客,可以全面的掌握mysql的常用知识,后续我也会陆续发出python相关的知识,关注我,和我一共进步吧! 1.SQL查询 1.执行顺序 ...
- python之斐波纳契数列
斐波纳契数列 斐波那契数列指的是这样一个数列 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233,377,610,987,1597,2584,4181,676 ...
- NopCommerce(Core)学习目录
1.NopCommerce下载运行 2.登录及权限 3.日志 4.依赖注入使用autofac 5.插件实现 ...
- visio画图ER图表和字段注释
最近年底属于验收的项目很多,大多数写文档中,数据库的设计ER图是比不可少的.下面记一下几个常用的用法.以下用的市visio版本为2007,由于菜单样式新版本可能有所不同,请对照相应功能进行操作! 1. ...
- jQuery的三种写法
jQuery的三种写法 jQuery一共有三种写法,写法如下: <script type="text/javascript" src="js/jquery-1.9. ...
- phpstrom怎样显示类的方法或函数列表
phpstorm是能显示类的函数或方法列表的. 打开phpstorm,鼠标放到编辑器的右下角(矩形加一个下划线,跟电视机的图标差不多),不用点击就能显示出来一个弹窗: 让后点击Structure,就出 ...
- 获取PHP页面的当前文件名(包括后缀名)
// $curPhp = substr($_SERVER['PHP_SELF'],strripos($_SERVER['PHP_SELF'],'/')+1); // print_r($_SERVER[ ...