crossfire 346# B

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.

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.

Examples

input

3 31 13 12 2

output

4 2 0 

input

5 21 55 1

output

16 9 

input

100000 1300 400

output

9999800001
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <cmath>
#include <vector>
#include <set>
using namespace std;
int main()
{
	 long long int n;
	 long long int m;
	 int a,b;
	 cin >> n >> m;
	 set <long long int> hang;
	 set <long long int> lie;//注意这里long long int 否则第一组数据都没法过
	 long long int total = n*n;
	 long long int new_hang;
	 long long int new_lie;
	 for(int i = 0; i < m; i++)
	 {
		 scanf("%d%d",&a,&b);
		 hang.insert(a);
		 lie.insert(b);
		 new_hang = n - hang.size();
		 new_lie = n -lie.size();
		 total = new_hang * new_lie;
		 cout << total << " ";

	 }

}

  

				
时间: 2024-11-09 04:11:27

crossfire 346# B的相关文章

8月5号=》346页-350页

13.11 创建对象 JavaScript中创建对象可以不用使用任何累.JavaScript中创建对象大概有3中方式. 13.11.1 使用new关键字调用构造器创建对象 代码示范: //定义一个函数,同时也定义了一个Person类 function Person(name,age) { this.name = name; this.age = age; } //使用new关键字创建Person实例 var p1 = new Person("张三",18); //输出该对象的属性值 a

iOS UIKit 框架 346 篇文档分类整理 - 预告

太阳火神的美丽人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用途-保持一致"创作公用协议 转载请保留此句:太阳火神的美丽人生 -  本博客专注于 敏捷开发及移动和物联设备研究:iOS.Android.Html5.Arduino.pcDuino,否则,出自本博客的文章拒绝转载或再转载,谢谢合作. 当前正在进行的是 "iOS Foundation 框架 224 篇相关文档分类整理",量很大,但会根据实际开发中的使用频繁程序

346. Moving Average from Data Stream

/* * 346. Moving Average from Data Stream * 2016-7-11 by Mingyang * 这里注意的就是(double) sum / count * sum需要转换成double才能继续往下除,因为不转的话最后不能成为整数14除以3等于4 */ class MovingAverage { public Queue<Integer> queue; public int sum = 0; public int si; public int count

Leetcode 346. Moving Average from Data Stream

Given a stream of integers and a window size, calculate the moving average of all integers in the sliding window. For example, MovingAverage m = new MovingAverage(3); m.next(1) = 1 m.next(10) = (1 + 10) / 2 m.next(3) = (1 + 10 + 3) / 3 m.next(5) = (1

SPOJ Problem 346:Bytelandian gold coins

有一种价值n的硬币能换成n/2,n/3,n/4的三个硬币,要求硬币价值的和尽可能多. 前十万打表,后面就BFS... #include<cstdio> #include<cstring> int a[100005]; int q[100005],l,r,t,i,n; long long ans; int main(){ for (i=0;i<=100000;i++){ a[i]=a[i/2]+a[i/3]+a[i/4]; if (i>a[i])a[i]=i; } whi

LeetCode 346. Moving Average from Data Stream (数据流动中的移动平均值)

Given a stream of integers and a window size, calculate the moving average of all integers in the sliding window. For example, MovingAverage m = new MovingAverage(3); m.next(1) = 1 m.next(10) = (1 + 10) / 2 m.next(3) = (1 + 10 + 3) / 3 m.next(5) = (1

Codeforces Round #346 (Div. 2) (659A,659B,659C,659D(几何叉乘),659E(并查集))

Round House 题目链接: http://codeforces.com/problemset/problem/659/A 解题思路: The answer for the problem is calculated with a formula ((a?-?1?+?b)  n + n)  n + 1. Such solution has complexity O(1). There is also a solution with iterations, modelling every o

Codeforces Round #346 (Div. 2)

前三题水 A #include <bits/stdc++.h> typedef long long ll; const int N = 1e5 + 5; int main() { int n, a, b; std::cin >> n >> a >> b; int bb = b; if (b < 0) bb = -b; while (bb--) { if (b < 0) { a--; } else { a++; } if (a == 0) { a

[leetcode]346. Moving Average from Data Stream滑动窗口平均值

Given a stream of integers and a window size, calculate the moving average of all integers in the sliding window. For example, MovingAverage m = new MovingAverage(3); m.next(1) = 1 m.next(10) = (1 + 10) / 2 m.next(3) = (1 + 10 + 3) / 3 m.next(5) = (1