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 ...
随机推荐
- 【字符串哈希】bzoj3098 Hash Killer II
教育我们做Rabin-Karp的时候一定要把模数取大?还是上溢好了. #include<cstdio> #include<cstdlib> using namespace st ...
- React Native使用Navigator组件进行页面导航报this.props....is not a function错误
在push的时候定义回调函数: this.props.navigator.push({ component: nextVC, title: titleName, passProps: { //回调 g ...
- PHP反射(ReflectionClass、ReflectionMethod)在ThinkPHP框架的控制器调度模块中的应用
ThinkPHP框架的控制器模块是如何实现 前控制器.后控制器,及如何执行带参数的方法? PHP系统自带的 ReflectionClass.ReflectionMethod 类,可以反射用户自定义类的 ...
- debian中添加sudo命令
解决方法(root命令) apt-get install sudochmod u+w /etc/sudoers //给此文件增加写入权限gedit /etc/sudoers找到root ALL=(AL ...
- 【jQuery】jquery中 使用$('#parentUid').attr(parentUid);报错jquery-1.11.3.min.js:5 Uncaught TypeError: Cannot read property 'nodeType' of undefined
jquery中 使用$('#parentUid').attr(parentUid);报错jquery-1.11.3.min.js:5 Uncaught TypeError: Cannot read p ...
- ORA-12537:TNS连接已关闭
安装完11i的VIS版本后,客户端连接数据时会报“ORA-12537:TNS连接已关闭”,在网上找到以下解决办法: 今天在远程客户端配置EBS数据库连接的时候发生“ORA-12537:TNS连接已 ...
- JS中的Math.pow(a,b)方法
定义和用法 pow() 方法可返回 x 的 y 次幂的值. 语法 Math.pow(x,y) 参数 描述 x 必需.底数.必须是数字. y 必需.幂数.必须是数字. 返回值 x 的 y 次幂. 说明 ...
- Go测试,功能测试,性能测试,测试辅助,go test 工具,高级测试,IO相关测试,黑盒测试,HTTP测试,进程测试
go命令教程: http://wiki.jikexueyuan.com/project/go-command-tutorial/0.5.html Go测试 第一个测试 “Hello Test!” 首先 ...
- HTML5 canvas图形库 RGraph【转】
RGraph是一个使用HTML5 Canvas标签实现的图表制作Library.利用该Library生成的Chart具有可交互性,当鼠标点击或移过时会显示相应的信息,可以动态加载Chart或对特殊点进 ...
- docker实战——构建Jekyll
构建第一个应用 要构建的第一个应用是Jekyll框架的自定义网站.我们会构建一下两个镜像. 一个镜像安装Jekyll以及其他用于构建Jekyll网站的必要的软件包. 一个镜像通过Apache来让Jek ...