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 ...
随机推荐
- 箭头函数 -------JavaScript
本文摘要:http://www.liaoxuefeng.com/ ES6标准新增了一种新的函数:Arrow Function(箭头函数). 为什么叫Arrow Function?因为它的定义用的就是一 ...
- ElasticSearch High Level REST API【6】获取集群信息
ElasticSearch 可以通过info()方法检索群集信息: public void info(){ RestHighLevelClient client = elasticClient.get ...
- 转:CentOS7 下 Redis4 安装与配置教程(Redis开机启动)
转 https://ken.io/note/centos7-redis4-setup 一.前言 1.本教程主要内容 Redis安装与测试 Redis远程访问配置 Redis开机启动配置 2.本教程环境 ...
- MySql学习笔记04
复习 day01 数据库相关: create database db4 character set utf8; show databases; show create database db4; dr ...
- ATM-db-dnhandler
import os,jsonfrom conf import settings def select(name): user_path = os.path.join(settings.BASE_DB, ...
- JZOJ 5838. 旅游路线 最大子段和
5838. 旅游路线 Time Limits: 1000 ms Memory Limits: 131072 KB Detailed Limits Goto ProblemSet Descrip ...
- 【转】iPhone通讯录AddressBook.framework和AddressBookUI.framework的应用
通讯录中联系人相关的应用iPhone提供了两个框架:AddressBook.framework和AddressBookUI.framework,使用这两个框架我们可以在程序中访问并显示iPhone数据 ...
- Gym - 101981D Country Meow(模拟退火)
题意 三维空间有\(n\)个点,找到另外一个点,离所有点的最大距离最小.求这个距离. 题解 \(1\).最小球覆盖,要找的点为球心. \(2\).模拟退火. 还是补一下模拟退火的介绍吧. 模拟退火有一 ...
- 洛谷 P3740 [HAOI2014]贴海报
题目描述 Bytetown城市要进行市长竞选,所有的选民可以畅所欲言地对竞选市长的候选人发表言论.为了统一管理,城市委员会为选民准备了一个张贴海报的electoral墙. 张贴规则如下: electo ...
- Linux命令之---rm
命令简介 rm命令为删除一个目录中的一个或多个文件或目录,它也可以将某个目录及其下的所有文件及子目录均删除.对于链接文件,只是删除了链接,原有文件均保持不变. rm是一个危险的命令,使用的时候要特别当 ...