比赛的时候 long long sum=n*n,计算不出1e10长度到数,没有搞掉。
哎,以后要注意这个地方。这个题其实不难:
统计能被攻击到的个数,然后用总的个数减掉就可以了。注意有些地方重复计算,要给去掉。
 
 
B. Cells Not Under Attack
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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.

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 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 

#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
int n,m;
scanf("%d%d",&n,&m);
long long sum=n;
sum*=sum;
int hang=;
int lie=;
int phang[];
int plie[];
for(int i=;i<=n+;i++){
phang[i]=plie[i]=;
}
long long goji=;
for(int i=;i<m;i++)
{
int tmp1,tmp2;
scanf("%d%d",&tmp1,&tmp2);
if(phang[tmp1]==&&plie[tmp2]==){
goji+=(n+n-);
goji-=lie;
goji-=hang;
}else if(phang[tmp1]!=&&plie[tmp2]==){
goji+=(n-);
goji-=(hang-);
}else if(phang[tmp1]==&&plie[tmp2]!=){
goji+=(n-);
goji-=(lie-);
}
if(phang[tmp1]==){
hang++;
}
if(plie[tmp2]==){
lie++;
}
phang[tmp1]++;
plie[tmp2]++;
printf("%I64d ",sum-goji); } int tmp1,tmp2;
scanf("%d%d",&tmp1,&tmp2);
if(phang[tmp1]==&&plie[tmp2]==){
goji+=((n*)-);
goji-=lie;
goji-=hang;
}else if(phang[tmp1]!=&&plie[tmp2]==){
goji+=(n-);
goji-=(hang-);
}else if(phang[tmp1]==&&plie[tmp2]!=){
goji+=(n-);
goji-=(lie-);
}
if(phang[tmp1]==){
hang++;
}
if(plie[tmp2]==){
lie++;
}
phang[tmp1]++;
plie[tmp2]++;
printf("%I64d\n",sum-goji); return ;
}

codeforces #364b Cells Not Under Attack的更多相关文章

  1. CodeForces 701B Cells Not Under Attack

    题目链接:http://codeforces.com/problemset/problem/701/B 题目大意: 输入一个数n,m, 生成n*n的矩阵,用户输入m个点的位置,该点会影响该行和该列,每 ...

  2. 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 ...

  3. Codeforces Round #364 (Div. 2) Cells Not Under Attack

    Cells Not Under Attack 题意: 给出n*n的地图,有给你m个坐标,是棋子,一个棋子可以把一行一列都攻击到,在根据下面的图,就可以看出让你求阴影(即没有被攻击)的方块个数 题解: ...

  4. codeforces 701B B. Cells Not Under Attack(水题)

    题目链接: B. Cells Not Under Attack 题意: n*n的棋盘,现在放m个棋子,放一个棋子这一行和这一列就不会under attack了,每次放棋子回答有多少点还可能under ...

  5. codeforces 701 B. Cells Not Under Attack

    B. Cells Not Under Attack time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  6. CF 701B Cells Not Under Attack(想法题)

    题目链接: 传送门 Cells Not Under Attack time limit per test:2 second     memory limit per test:256 megabyte ...

  7. Cells Not Under Attack

    Cells Not Under Attack Vasya has the square chessboard of size n × n and m rooks. Initially the ches ...

  8. cf701B Cells Not Under Attack

    Vasya has the square chessboard of size n × n and m rooks. Initially the chessboard is empty. Vasya ...

  9. Codeforces Round #364

    http://codeforces.com/contest/701 A - Cards 水 // #pragma comment(linker, "/STACK:102c000000,102 ...

随机推荐

  1. [CF911D]Inversion Counting

    题目大意: 给你一个数列,翻转其中一个区间,问每次翻转过后逆序对个数的奇偶性. 思路: 首先树状数组求出一开始的奇偶性,然后考虑每次翻转对答案的贡献. 对于整个区间,我们可以把翻转转化成若干次交换. ...

  2. Java多线程——ReentrantReadWriteLock源码阅读

    之前讲了<AQS源码阅读>和<ReentrantLock源码阅读>,本次将延续阅读下ReentrantReadWriteLock,建议没看过之前两篇文章的,先大概了解下,有些内 ...

  3. 如何让Ubuntu 14重启后,保存屏幕亮度的设置

    每次重新启动后,系统的屏幕亮度都会被调节到最大值,挺烦人的!如何让它保存设置值呢? 首先,我们必须知道自己系统的屏幕亮度取值范围,打开终端,按照下面的步骤进行: 进入backlight这个目录 cd ...

  4. 笔记:git基本操作

    原文: http://www.cnblogs.com/pingwen/p/8098035.html 1. 快速入门的基本概念 相比SVN,TFS等集中式的版本管理系统,GIT分布式管理最重要的理念是本 ...

  5. YUV12(420) (from)to RGB24

    直接上代码 #include <opencv2/opencv.hpp> #include <stdio.h> #define min(a,b) ((a<b)?a:b) # ...

  6. 奇特的JavaScript连续赋值运算

    一.引子: }; a.x = a = {n:}; alert(a.x); // --> undefined 以上第二句 a.x = a = {n:2} 是一个连续赋值表达式.这个连续赋值表达式在 ...

  7. prometheus的坑

    prometheus是一个用于监控k8s集群状态的工具.今天在主机上配置这个东西,遇到了一个坑,调查了一段时间才解决,记之. 首先,根据网上的教程,利用helm安装这个东西很方便,只要三条指令(ref ...

  8. Spark(五) -- Spark Streaming介绍与基本执行过程

    Spark Streaming作为Spark上的四大子框架之一,肩负着实时流计算的重大责任 而相对于另外一个当下十分流行的实时流计算处理框架Storm,Spark Streaming有何优点?又有何不 ...

  9. 【千纸诗书】—— PHP/MySQL二手书网站后台开发之功能实现

    前言:前一篇温习了网站开发需要掌握的基础知识,这一篇重点梳理一下各个功能模块的[详细设计与实现].项目github地址:https://github.com/66Web/php_book_store, ...

  10. Linux文件夹、分区

    必须明确,硬盘分区的存在,是由硬盘的物理特性决定的,不会因为操作系统的不同而有所改变 所以不用对为根目录/挂载分区的同时还为/usr挂载分区感到惊讶   ====分区的概念==== 可以把一个硬盘比成 ...