codeforces 701 B. 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
分析:这道题刚开始没做出来,看了题解。这道题说让你放棋子,当把这个棋子放下后当前行和当前列都会受到这个棋子的攻击,问你,当放下一个棋子后没有受到攻击的格子还有多少。其实只要统计那些行那些列被棋子占据了即可。用两个set分别保存当前状态下那些行那些列被占据,然后用总棋子数(n*n) 减去被占的行数即:r.size() * n,和被占的列数即: (n - 已受到影的行) ( n - r.size()) * l.size(); 就完成了。
/*************************************************************************
> File Name: cfC.cpp
> Author:
> Mail:
> Created Time: 2016年08月08日 星期一 13时42分35秒
************************************************************************/ #include<iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
set<ll> r,l; int main()
{
ios::sync_with_stdio(false);
cin.tie();
ll n,m;
cin >> n >> m;
ll x,y;
ll ans;
ll flag = ;
while(m--)
{
cin >> x >> y;
r.insert(x);
l.insert(y);
ans = n * n - r.size() * n - (n - r.size()) * l.size();
if(flag)
cout << ' ';
cout << ans;
flag++;
}
cout << endl;
return ;
}
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.
codeforces 701 B. Cells Not Under Attack的更多相关文章
- codeforces 701B B. Cells Not Under Attack(水题)
题目链接: B. Cells Not Under Attack 题意: n*n的棋盘,现在放m个棋子,放一个棋子这一行和这一列就不会under attack了,每次放棋子回答有多少点还可能under ...
- 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长度到数,没有搞掉. 哎,以后要注意这个地方.这个题其实不难: 统计能被攻击到的个数,然后用总的个数减掉就可以了.注意有些地方重复计算, ...
- 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 ...
- CodeForces 701B Cells Not Under Attack
题目链接:http://codeforces.com/problemset/problem/701/B 题目大意: 输入一个数n,m, 生成n*n的矩阵,用户输入m个点的位置,该点会影响该行和该列,每 ...
- Codeforces Round #115 A. Robot Bicorn Attack 暴力
A. Robot Bicorn Attack Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/17 ...
- cf701B Cells Not Under Attack
Vasya has the square chessboard of size n × n and m rooks. Initially the chessboard is empty. Vasya ...
随机推荐
- 《Craking the Coding interview》python实现---02
###题目:翻转一个字符串###思路:从字符串的最后一位开始,依次取###实现:伪代码.函数.类实现#伪代码: #01string=sNew_s=""for i in range( ...
- 紫书 习题 8-25 UVa 11175 (结论证明)(配图)
看了这篇博客https://blog.csdn.net/u013520118/article/details/48032599 但是这篇里面没有写结论的证明, 我来证明一下. 首先结论是对于E图而言, ...
- C#调用带结构体指针的C Dll的方法
在C#中调用C(C++)类的DLL的时候,有时候C的接口函数包含很多参数,而且有的时候这些参数有可能是个结构体,而且有可能是结构体指针,那么在C#到底该如何安全的调用这样的DLL接口函数呢?本文将详细 ...
- 洛谷—— P2983 [USACO10FEB]购买巧克力Chocolate Buying
https://www.luogu.org/problem/show?pid=2983 题目描述 Bessie and the herd love chocolate so Farmer John i ...
- ftoa浮点型转换成字符串
#include <stdio.h> bool ftos(float num,char *s,int n) { int temp; float t=num; int pn=0; b ...
- 用java实现螺旋数组
接收数组的行数和列数,返回正序和倒序的螺旋数组 package cn.baokx; public class Test { public static void main(String[] args) ...
- spark pipeline 例子
""" Pipeline Example. """ # $example on$ from pyspark.ml import Pipeli ...
- 6.CPU调度
总论:所有的程序都是CPU和I/O等待交替执行 CPU调度器的操作时机 调用CPU调度器的时机,通常发生在 某一进程从执行状态转化为等待状态 某一进程从执行状态转化为就绪状态 某一进程从等待状态转为就 ...
- MyBatis的架构设计以及实例分析--转
原文地址:http://blog.csdn.net/luanlouis/article/details/40422941 MyBatis是目前非常流行的ORM框架,它的功能很强大,然而其实现却比较简单 ...
- [转]Zen Cart官网屏蔽中国用户访问的真正原因
近需要到 zen cart 的官方网站查询一些资料,却发现无法访问!在网上搜索一番以后,原来如此. Zen Cart官网屏蔽中国用户访问的真正原因 作者:[鹏程万里] 日期:2011-03-26 准备 ...