Codeforces Round #364 (Div. 2) B. Cells Not Under Attack 标记数组
来源:互联网 发布:热云数据 编辑:程序博客网 时间:2024/04/27 06:43
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 31 13 12 2
4 2 0
5 21 55 1
16 9
100000 1300 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<algorithm>#include<cstring>#include<cstdio>#include<string>using namespace std;#define N 6000#define INF 1e9+5long long a[1000100];long long b[1000100];long long ans[1000100];long long n, m, x, y;int main(){long long i, j;scanf("%I64d%I64d", &n, &m);long long x = n, y = n;for (i = 1; i <= m; i++){long long x1, y1;scanf("%I64d%I64d", &x1, &y1);if (a[x1] == 0){x--;a[x1] = 1;}if (b[y1] == 0){y--;b[y1] = 1;}ans[i] = x*y;}for (i = 1; i <= m; i++){if (i == 1) printf("%I64d", ans[i]);else printf(" %I64d", ans[i]);}printf("\n");return 0;}
- Codeforces Round #364 (Div. 2) B. Cells Not Under Attack 标记数组
- Codeforces Round #364 (Div. 2) B. Cells Not Under Attack
- CF #364 (Div. 2) (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(数学)
- Codeforces Round #364 (Div. 2), problem: (B) Cells Not Under Attack
- codeforces Round #364(Div.2)701B. Cells Not Under Attack ( math)
- 【Codeforces Round 364 (Div 2)B】【简单讨论】Cells Not Under Attack 行列炮台覆盖不被攻击格子数
- 【数论】CF#364 div.2 B.Cells Not Under Attack
- Codeforces #364(Div.2)B.Cells Not Under Attack 【思维】
- 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#364(Div.2)B.Cell Not Under Attack
- B. Cells Not Under Attack
- B - Cells Not Under Attack
- Cells Not Under Attack (棋盘)(标记数组)
- 卡特兰数(Catalan Number)
- JavaSE面试题【每天一整理】
- UVA - 202 Repeating Decimals
- Notepad++进行php开发所必需的插件【转】
- POJ 2975 Nim <Nim 博弈>
- Codeforces Round #364 (Div. 2) B. Cells Not Under Attack 标记数组
- Git从菜鸟到入门到放弃
- java-基础-异常
- Bestcoder-Aaronson
- sql语句优化(一)
- java值传递,引用传递
- TCP/IP协议栈及OSI参考模型详解
- 杭电ACM--HDU-2053a/b+c/d和HDU-2504又见gcd
- CodeForces 427A Police Recruits