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 arenot 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 <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#include <ext/rope>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define vi vector<int>
#define pii pair<int,int>
#define mod 1000000007
#define inf 0x3f3f3f3f
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
const int maxn=1e5+;
const int dis[][]={{,},{-,},{,-},{,}};
using namespace std;
using namespace __gnu_cxx;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
int n,m,x,y,cnt1,cnt2;
bool a[maxn],b[maxn];
int main()
{
int i,j,k,t;
scanf("%d%d",&n,&m);
ll now=1ll*n*n;
while(m--)
{
scanf("%d%d",&x,&y);
if(!a[x])
{
now-=n;
now+=cnt2;
}
if(!b[y])
{
now-=n;
now+=cnt1;
}
if(!a[x])cnt1++;
if(!b[y])cnt2++;
if(!a[x]&&!b[y])now++;
a[x]=b[y]=true;
printf("%lld ",now);
}
//system ("pause");
return ;
}
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个坐标,是棋子,一个棋子可以把一行一列都攻击到,在根据下面的图,就可以看出让你求阴影(即没有被攻击)的方块个数 题解: ...
- 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 ...
- cf701B Cells Not Under Attack
Vasya has the square chessboard of size n × n and m rooks. Initially the chessboard is empty. Vasya ...
- 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 ...
随机推荐
- ios设置textField只能输入数字用于电话号码
首先在.xib中将UITextField的Keyboard设置为Number Pad,但是使用时键盘会切回别的键盘无法对内容进行校验.通过神奇的百度我知道了通过以下方法可以解决这样的问题: 首先让.x ...
- vmware 安装提示the msi failed
原因是卸载不干净,使用批处理bat文件卸载,然后重启即可. VMware workstation 10.0序列号:MA491-6NL5Q-AZAM0-ZH0N2-AAJ5A 百度云文件:http:// ...
- c语言-转义序列
字符组合是由反斜杠 (\) 后接字母或位组合构成的字符组合.若要显示换行符,单引号或某些其他字符在字符串末尾,必须使用转义序列. 转义序列被视为单个字符,因此,它是有效的字符常数. 转义序列通常用于指 ...
- TD配置安装方式
TD服务器搭建及配置指南 第一:安装前的环境准备 系统需安装IIS作为web服务器(停止IIS的smtp服务). 选择SQL Server2000作为数据库.Win2003需安装SP3. 以管理员登陆 ...
- Windows常用的监视数据指标
- git 忽略已跟踪的文件
对于未跟踪的文件,可以编辑.gitignore文件进行忽略. 对于已跟踪的文件,编辑.gitignore文件不会起作用,它只针对未被跟踪的文件,也就是你先设置规则,然后添加的新文件符合这些规则的就会被 ...
- Ubuntu14.04+cuda 7.5+cudnn_v4+tensorflow安装
系统环境:Ubuntu14.04 64位.Windows7 64位 双系统 CUDA 版本: 7.5 总结一下,我的安装建议是: 一定要下一份CUDA官方的安装文档,按照它的步骤一步步慢慢来,不可偷懒 ...
- myeclipse复制项目
一.myEclipse 复制后修改名称,访问不到项目 这是因为,你只是改了项目的名称,而没有改 下面是解决方法: 方法 1.右击你的项目,选择"properties",在" ...
- 【stack】模拟网页浏览 poj 1028
#include<stdio.h> #include<string.h> int main() { ][]; ]; int i,depth; strcpy(s[]," ...
- Happy Matt Friends
Happy Matt Friends Time Limit: 6000/6000 MS (Java/Others) Memory Limit: 510000/510000 K (Java/Oth ...