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 ...
随机推荐
- jquery效果,多个div,点击任何一个div,那么这个div会切换文字,变换背景颜色,再次点击其他的div ,这个div会发生刚才的变化,之前点击的div的颜色会变回来
首先css样式: /*原来的背景色*/ .bg { background:'red' } /*需要切换的背景色*/ .bg_click { background:'green' } JS: $('di ...
- webform在页面生成的代码与事件回传
<script type="text/javascript"> //<![CDATA[ var theForm = document.forms['form1'] ...
- c语言-经验之谈
如果你是一个大牛,那就直接忽略这里. 如果你是一个新手,请继续向下看. 在自学计算机的路上真的很悲惨,如果你是在学校里面学习还算比较幸运. 针对编程来说,在学校里面学习的只是学会了语言,而很少有人学会 ...
- Eclipse配置--智能补全
定位到:Windows→Preferences→Java→Editor→Content Assist 将Auto Activation triggers for java的默认值“.”修改为" ...
- hdu_5676_ztr loves lucky numbers
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5676 在这%一下安神,用了我没见过的黑科技next_permutation,至少我是今天才知道的 #i ...
- 求最大公约数(GCD)的两种算法
之前一直只知道欧几里得辗转相除法,今天学习了一下另外一种.在处理大数时更优秀的算法--Stein 特此记载 1.欧几里得(Euclid)算法 又称辗转相除法,依据定理gcd(a,b)=gcd(b,a% ...
- viewpager处理(二):设置当前item时,让viewpager不出现滑动动画
我们在使用viewpager.setCurrentItem(position);的时候,viewpager出现滑动动画,如何去掉这个动画呢? 可以用viewpager.setCurrentItem(p ...
- asp.net控件ControlToValidate同OnClientClick冲突解决办法
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" Error ...
- 图解如何 将Excel里的数据导入到sql server数据库中
项目中,经常会碰到如何将Excel里的数据导入到sql server中的问题. 下面,图解如何实现导入Excel中的数据到sql server 2008 R2: Excel截图如下: 查询pub数据库 ...
- sql server 数据库导出表里所有数据成insert 语句
有时候,我们想把数据库的某张表里的所有数据导入到另外一个数据库或另外一台计算机上的数据库,对于sql server有这样的一种方法 下面我以sql server 2008 R2,数据库是Northwi ...