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.
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
#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 << " ";
}
}
crossfire 346# B的更多相关文章
- 1Z0-053 争议题目解析346
1Z0-053 争议题目解析346 考试科目:1Z0-053 题库版本:V13.02 题库中原题为: 346.What is the impact of the results of the outp ...
- Codeforces Round #346 (Div. 2)---E. New Reform--- 并查集(或连通图)
Codeforces Round #346 (Div. 2)---E. New Reform E. New Reform time limit per test 1 second memory lim ...
- 波音,自动驾驶bug未修复,致346人丧生!5个月内两次坠毁!其中,包括8名中国公民
一,波音737 MAX再次坠毁 继2018年10月29日,印尼波音737MAX飞机坠入爪哇海,导致178名乘客不幸遇难后,时隔不足5月,上周日,埃塞俄比亚航空公司一架波音737MAX客机在飞往肯尼亚途 ...
- Linux下Git命令中文显示乱码的问题解决:274\232\350\256\256\346\200\273\347\273\223
使用git add添加要提交的文件的时候,如果文件名是中文,会显示形如274\232\350\256\256\346\200\273\347\273\223的乱码. 解决方案:在bash提示符下输入: ...
- 【转载】#346 - Polymorphism
Recall that polymorphism is one of the three core principles of object-oriented programming. Polymor ...
- 346. Moving Average from Data Stream
/* * 346. Moving Average from Data Stream * 2016-7-11 by Mingyang * 这里注意的就是(double) sum / count * su ...
- <Design> 359 346
359. Logger Rate Limiter 用map搭建. class Logger { HashMap<String, Integer> map; /** Initialize y ...
- Codeforces Round #346 (Div. 2)E - New Reform(DFS + 好题)
E. New Reform time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- 百度编辑器UEditor ASP.NET示例Demo 分类: ASP.NET 2015-01-12 11:18 346人阅读 评论(0) 收藏
在百度编辑器示例代码基础上进行了修改,封装成类库,只需简单配置即可使用. 完整demo下载 版权声明:本文为博主原创文章,未经博主允许不得转载.
随机推荐
- ip接口调用
<?php header("Content-type: text/html; charset=utf-8"); function getIP(){ if (isset($_S ...
- 介绍TableView非常不错的一篇文章
原文:http://blog.csdn.net/fanxiaochuan/article/details/11332775 介绍TableView非常不错的一篇文章: http://www.cocoa ...
- c++primerplus(第六版)编程题——第5章(循环和关系表达式)
声明:作者为了调试方便,每一章的程序写在一个工程文件中,每一道编程练习题新建一个独立文件,在主函数中调用,我建议同我一样的初学者可以采用这种方式,调试起来会比较方便. (具体方式参见第3章模板) 1. ...
- 连接池dbcp pool
-package cn.gdpe.pool; import java.io.InputStream;import java.sql.Connection;import java.sql.Prepare ...
- php之购物车类思路及代码
<?php /* 购物车类 1.整站范围内,购物车--全局有效 解决:把购物车的信息,放在session里 2.既然全局有效,购物车的实例只有一个 解决:单例模式 技术选型:session+单例 ...
- MAC 开发工具
web开发编辑器 Espresso下载地址 密码: i9hr
- Mvc Controller 单元测试 Mock User.Identity.Name
被测试的Action 包含 User.Identity.Name 代码,在写测试代码需要Mock ControllerContext对象 代码如下: var mock = new Mock<Co ...
- Ruby自学笔记(二)— Ruby的一些基础知识
Ruby安装好之后,我们就可以来实践Ruby语言了. 以下是一些学习到的简单基础知识: 1. 如何执行Ruby文件? 我们编写的Ruby文件是以rb为后缀名的,例如:XXX.rb.当要执行ruby文件 ...
- golang 性能
服务器: 阿里云ECS:1核1G内存,CentOS6.5 x64 返回内容: {"ErrInfo":{"ErrCode":0,"ErrMsg" ...
- TortoiseSVN 的分支合并操作
今天对svn的分支合并有了兴趣,所以对新建了一个项目练练手. 在网上找了一篇文章做指导: http://www.open-open.com/lib/view/open1346982569725.htm ...