题目链接: 传送门

Cells Not Under Attack

time limit per test:2 second     memory limit per test:256 megabytes

Description

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.

Sample Input

3 3
1 1
3 1
2 2

5 2
1 5
5 1

100000 1
300 400

Sample Output

4 2 0

16 9

9999800001 

解题思路:

题目大意:N*N的棋盘大小,往(x,y)放一棋子,则x行y列的棋格都会被攻击,每次放下一个棋子,问剩下还有多少没被攻击的棋格。
这道题如果根据棋子放下位置去特判计算显得很复杂,可以按行、列来做,我首先先做列的,每次放下的棋子如果在新的一列那么肯定要减号N个棋格,如果之前已经有行被减掉,那么就不能减去N个棋格那么多,不然会有重复减,加个变量记录有几行被减去计算一下就好了,行同理。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef __int64 LL;

int main()
{
    LL N,M;
    while (~scanf("%I64d%I64d",&N,&M))
    {
        LL sum = N*N;
        LL x,y,xcnt = 0,ycnt = 0;
        bool r[100005],c[100005];
        memset(r,false,sizeof(r));
        memset(c,false,sizeof(c));
        bool first = true;
        while (M--)
        {
            scanf("%I64d%I64d",&x,&y);
            if (!c[y])
            {
                sum -= (N - xcnt);
                c[y] = true;
                ycnt++;
            }
            if (!r[x])
            {
                sum -= (N - ycnt);
                r[x] = true;
                xcnt++;
            }
            first?printf("%I64d",sum):printf(" %I64d",sum);
            first = false;
        }
        printf("\n");
    }
    return 0;
}

CF 701B Cells Not Under Attack(想法题)的更多相关文章

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

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

  2. CodeForces 701B Cells Not Under Attack

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

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

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

  4. codeforces #364b Cells Not Under Attack

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

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

  6. HDU 4972 Bisharp and Charizard 想法题

    Bisharp and Charizard Time Limit: 1 Sec  Memory Limit: 256 MB Description Dragon is watching NBA. He ...

  7. CodeForces 111B - Petya and Divisors 统计..想法题

    找每个数的约数(暴力就够了...1~x^0.5)....看这约数的倍数最后是哪个数...若距离大于了y..统计++...然后将这个约数的最后倍数赋值为当前位置...好叼的想法题.... Program ...

  8. Cells Not Under Attack

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

  9. HDU - 5806 NanoApe Loves Sequence Ⅱ 想法题

    http://acm.hdu.edu.cn/showproblem.php?pid=5806 题意:给你一个n元素序列,求第k大的数大于等于m的子序列的个数. 题解:题目要求很奇怪,很多头绪但写不出, ...

随机推荐

  1. Spring 依赖注入方式详解

    平常的Java开发中,程序员在某个类中需要依赖其它类的方法. 通常是new一个依赖类再调用类实例的方法,这种开发存在的问题是new的类实例不好统一管理. Spring提出了依赖注入的思想,即依赖类不由 ...

  2. 特殊约束From To

    说实话这个不太懂,没用过也没有遇到相应的情况(或者说我不知道).大家可以更多的去参考特定约束FROM TO和MicroZed开发板笔记,第72部分:多周期约束等内容. 本文待修正 系列目录      ...

  3. PHP中JSON的跨域调用

    主调文件index.html <script type="text/javascript"> function getProfile(str) { var arr = ...

  4. wap端开发必须基础

    1. nitial-scale=1.0 确保网页加载时,以 1:1 的比例呈现,不会有任何的缩放. 在移动设备浏览器上,通过为 viewport meta 标签添加 user-scalable=no  ...

  5. Hibernate Synchronizer3——一个和hibernate Tool类似的小插件之使用方法

    首先,要告诉大家的是,当我们要自动生成Mapping File的时候,我们除了使用hibernae tools之外,还可以通过一个更为简洁的插件,只需通过点击: 1.Hibernate Configu ...

  6. Day Six(Beta)

    站立式会议 站立式会议内容总结 331 今天:完成闹钟功能,远程数据库采用bmob的解决方案,应用初始化bmob 遇到问题:闹钟没有取消提醒 以及多次设置提醒的问题 明天:修改闹钟问题,完成文件下载( ...

  7. 手把手windows64位配置安装python2.7

    这几天公司要用到python的一些算法,让我调研一番,之前对Python一次没接触的我在安装配置环境的时候由于版本的问题,折腾了好久,这里简单介绍一下我的安装方法,需要安装pyhton的朋友可以不再向 ...

  8. [转]PL/SQLDeveloper导入导出Oracle数据库方法

    原文地址:http://www.2cto.com/database/201405/305452.html 1.Oracle数据库导出步骤 1.1 Tools→Export User Objects.. ...

  9. 【BZOJ 2194】快速傅立叶之二

    随便代换一下把它变成多项式乘法,及$C[T]=\sum_{i=0}^{T}A[i]×B[T-i]$这种形式,然后FFT求一下就可以啦 #include<cmath> #include< ...

  10. 二叉查找树 C++实现(含完整代码)

    一般二叉树的查找是通过遍历整棵二叉树实现,效率较低.二叉查找树是一种特殊的二叉树,可以提高查找的效率.二叉查找树又称为二叉排序树或二叉搜索树. 二叉查找树的定义 二叉排序树(Binary Search ...