比赛的时候 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. 【二维单调队列】BZOJ1047-[HAOI2007]理想的正方形

    [题目大意] 有一个a*b的整数组成的矩阵,现请你从中找出一个n*n的正方形区域,使得该区域所有数中的最大值和最小值的差最小. [思路] 裸的二维单调队列.二维单调队列的思路其实很简单: (1)对于每 ...

  2. openresty的ngx.timer.at

    openresty的ngx.timer.at真是个强大的方法. 例如某些函数不可以在一些NGINX的执行阶段使用时,可以ngx.timer.at API 创建一个零延迟的timer,在timer中去处 ...

  3. 美团在Redis上踩过的一些坑-3.redis内存占用飙升(转载)

     一.现象:     redis-cluster某个分片内存飙升,明显比其他分片高很多,而且持续增长.并且主从的内存使用量并不一致.   二.分析可能原因:  1.  redis-cluster的bu ...

  4. 如何设断点????-----使用WinDbg调试SQL Server查询

    http://www.cnblogs.com/woodytu/p/4665427.html http://www.sqlservercentral.com/blogs/aschenbrenner/20 ...

  5. JAVA常见算法题(二十六)

    package com.xiaowu.demo; import java.util.Scanner; /** * Java实现将阿拉伯数字转为汉字 * * @author WQ * */ public ...

  6. Solr6.6 配置中文分词库mmseg4j

    1.准备 首先安装solr:参照搜索引擎Solr-6.6.0搭建,如果版本高于6,可能会不支持,需要改mmseg4j包 mmseg4j包下载: mmseg4j-solr-2.3.0-with-mmse ...

  7. Python 转义html中以"&#"开头的字符

    from HTMLParser import HTMLParser print HTMLParser().unescape('中国')

  8. Foundation框架 - NSNumber类

    NSNumber类 NSFormatter #import <Foundation/Foundation.h> int main(int argc, const char * argv[] ...

  9. poj_1284_原根

    一開始看题的时候第一想法就是暴力,可是无奈数据量有点大,看了题解之后才知道原来牵扯到数论上的一个叫做原根的东西,这个题的题意就是,给你一个奇素数,问题他的原根有多少.依据初等数论上所说,此时牵扯到了三 ...

  10. 补番计划 (长沙理工大学第十一届程序设计竞赛)(双端队列+set容器+string)

    补番计划 Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other) Total Submissi ...