文章标题 codeforces 701B:Cells Not Under Attack(水+set)
来源:互联网 发布:贴吧爆吧软件安卓 编辑:程序博客网 时间:2024/05/18 17:26
Cells Not Under Attack
Description
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.
Input
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.
Output
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.
Sample Input
Input
3 3
1 1
3 1
2 2
Output
4 2 0
Input
5 2
1 5
5 1
Output
16 9
Input
100000 1
300 400
Output
9999800001
题意:在一个空的n*n的棋盘上放车,放上的车的列和行就被覆盖了,题目然我们输出没放一个棋子,剩下没被覆盖的数目
分析:可以用set记录已经被放过棋子的行和列,然后:总格子数-行n+列*n-行列。
代码:
#include<iostream>#include<string>#include<cstdio>#include<cstring>#include<vector>#include<math.h>#include<queue> #include<set>#include<algorithm>using namespace std;long long n;long long m;long long x[100005],y[100005];set <long long>hang;set <long long>lie;int main (){ while (scanf ("%lld%lld",&n,&m)!=EOF){ hang.clear() ; lie.clear() ; for (int i=0;i<m;i++){ scanf ("%lld%lld",&x[i],&y[i]); } long long sum=n*n; for (int i=0;i<m;i++){ hang.insert(x[i]); lie.insert(y[i]); long long temp1=sum; long long t1=hang.size() ; long long t2=lie.size() ; long long temp=t1 * n+t2 *n-t1 *t2 ; temp1-=temp; if (i==0)printf ("%lld",temp1); else printf (" %lld",temp1); } printf ("\n"); } return 0;}
- 文章标题 codeforces 701B:Cells Not Under Attack(水+set)
- codeforces--701B Cells Not Under Attack
- CodeForces 701B Cells Not Under Attack
- CodeForces 701B Cells Not Under Attack
- codeforces B. Cells Not Under Attack (数学)
- Codeforces 701B Cells Not Under Attack(模拟)
- 【Codeforces】-701B-Cells Not Under Attack(思维,好)
- 【CodeForces】701B - Cells Not Under Attack(思维)
- CodeForces 701B Cells Not Under Attack 思维题
- B. Cells Not Under Attack
- B - Cells Not Under Attack
- Codeforces Round #364(Div. 2) A. Cards【模拟】 && B. Cells Not Under Attack【SET/规律】
- Codeforces Round #364 (Div. 2) B. Cells Not Under Attack
- 【打CF,学算法——三星级】CodeForces 701B Cells Not Under Attack (分析)
- codeforces Round #364(Div.2)701B. Cells Not Under Attack ( math)
- Cells Not Under Attack
- Codeforces #364(Div.2)B.Cells Not Under Attack 【思维】
- Codeforces Round #364 (Div. 2) B. Cells Not Under Attack 标记数组
- Object 三个常用方法复习
- linux 下mysql忘记密码解决方法
- java中解析一个json串,本文详细介绍了安卓原生的解析以及用fastjson解析
- 树的基本操作
- 怎么用js对获取的date进行比较
- 文章标题 codeforces 701B:Cells Not Under Attack(水+set)
- android5.1 单次下滑直接切到quick setting
- (零)ArcGIS API For JavaScript3.17本地部署(Tomcat)
- 1110. Complete Binary Tree (25)
- 多校联合训练7&&HDU5813
- HDU1503(记录公共子序列)
- POJ2299——Ultra-QuickSort
- PHP假期复习(一)----编程入门
- 多重背包的两种解决方法(poj1276)