比赛的时候 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. jvm-监控指令-jstack

    格式: jstack [option] vmid 选项: -l 除了堆栈信息外,显示关于锁的附加信息. 作用: 生成虚拟机当前时刻的线程快照. 目的: 定位线程长时间停顿的原因,比如线程间死锁.死循环 ...

  2. 分析器错误 未能加载类型“XX.WebApiApplication”

    解决方案,删除bin目录下内容(有单独使用dll的删除前请先备份) 清理解决方案并重新生成

  3. vb6 wininet

    Private Const UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; .NET CLR 1.1.4322)&qu ...

  4. Linux下获取本机IP地址的代码

    Linux下获取本机IP地址的代码,返回值即为互联网标准点分格式的字符串. #define ETH_NAME "eth0" //获得本机IP地址 char* GetLocalAdd ...

  5. “DllRegisterServer的调用失败”问题解决办法(转)

    在日常的工作中,用regsvr32 命令注册dll组件是,会碰到模块"xxx.dll"已加载,但DllRegisterServer的调用失败.特别是再在xp的系统上能正确注册,但是 ...

  6. [Python爬虫] 之二十五:Selenium +phantomjs 利用 pyquery抓取今日头条网数据

    一.介绍 本例子用Selenium +phantomjs爬取今日头条(http://www.toutiao.com/search/?keyword=电视)的资讯信息,输入给定关键字抓取资讯信息. 给定 ...

  7. centos7安装ifconfig命令

    ifconfig命令是设置或显示网络接口的程序,可以显示出我们机器的网卡信息,可是有些时候最小化安装CentOS等Linux发行版的时候会默认不安装ifconfig等命令,这时候你进入终端,运行ifc ...

  8. [加入用户]解决useradd 用户后没有加入用户Home文件夹的情况,Linux改变文件或文件夹的訪问权限命令,linux改动用户password,usermod的ysuum安装包。飞

    usermod的yum安装包: shadow-utils 将nobody用户加入到nogroup 组: usermod -g nogroup nobody cat /etc/passwd|grep n ...

  9. Jfinal极速开发微信系列教程(三)--------------对JSP的支持以及部署Tomcat运行异常问题

    本文章主要解决以下问题: 1.Jfianl对JSP的支持2.Jfianl Maven项目部署到Tomcat,启动项目异常问题解决 第一个问题重现截图解决方案:1.在configConstant中添加视 ...

  10. WIN7怎样把屏幕改为16位色

    1 右击桌面,选择屏幕分辨率   2 选择高级设置   3 点击"监视器"选项卡,把颜色改为16位.   4 屏幕会暂时黑屏一段时间,随后主题将自动切换为基础版(失去Areo效果) ...