codeforces #364b Cells Not Under Attack

比赛的时候 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 31 13 12 2

output

4 2 0 

input

5 21 55 1

output

16 9 

input

100000 1300 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=0;
    int lie=0;
    int phang[100005];
    int plie[100005];
    for(int i=0;i<=n+5;i++){
        phang[i]=plie[i]=0;
    }
    long long goji=0;
    for(int i=1;i<m;i++)
    {
        int tmp1,tmp2;
        scanf("%d%d",&tmp1,&tmp2);
        if(phang[tmp1]==0&&plie[tmp2]==0){
            goji+=(n+n-1);
            goji-=lie;
            goji-=hang;
        }else if(phang[tmp1]!=0&&plie[tmp2]==0){
            goji+=(n-1);
            goji-=(hang-1);
        }else if(phang[tmp1]==0&&plie[tmp2]!=0){
            goji+=(n-1);
            goji-=(lie-1);
        }
        if(phang[tmp1]==0){
            hang++;
        }
        if(plie[tmp2]==0){
            lie++;
        }
        phang[tmp1]++;
        plie[tmp2]++;
        printf("%I64d ",sum-goji);

    }

    int tmp1,tmp2;
        scanf("%d%d",&tmp1,&tmp2);
        if(phang[tmp1]==0&&plie[tmp2]==0){
            goji+=((n*2)-1);
            goji-=lie;
            goji-=hang;
        }else if(phang[tmp1]!=0&&plie[tmp2]==0){
            goji+=(n-1);
            goji-=(hang-1);
        }else if(phang[tmp1]==0&&plie[tmp2]!=0){
            goji+=(n-1);
            goji-=(lie-1);
        }
        if(phang[tmp1]==0){
            hang++;
        }
        if(plie[tmp2]==0){
            lie++;
        }
        phang[tmp1]++;
        plie[tmp2]++;
        printf("%I64d\n",sum-goji);

        return 0;
}

时间: 2024-10-14 12:43:14

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

Codeforces 701B. Cells Not Under Attack

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

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

题目链接: B. Cells Not Under Attack 题意: n*n的棋盘,现在放m个棋子,放一个棋子这一行和这一列就不会under attack了,每次放棋子回答有多少点还可能under attack; 思路:对行和列标记; AC代码: #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #incl

cf701B Cells Not Under Attack

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

Cells Not Under Attack

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

Educational Codeforces Round 73 (Rated for Div. 2) B. Knights(构造)

链接: https://codeforces.com/contest/1221/problem/B 题意: You are given a chess board with n rows and n columns. Initially all cells of the board are empty, and you have to put a white or a black knight into each cell of the board. A knight is a chess pi

Codeforces Round #364 (Div. 2) ABCDE

A. Cards 题解: 目的是将n个数分成n/2个人,每个人2个,要求和一样,保证有解 排序一下再选取就行了 代码: #include<bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define se second #define fs first #define ll long long typedef pair<int,int> P; const int INF=1

Codeforces Round #364 (Div. 2) - A B C

A - Cards /* 题意 : 有 n 张牌 ,每张牌都有一个数值 ,分给 n/2 个人 ,每个人手中的牌的数值加起来要相等, 一张牌只可分一个人. ( n 是偶数 ,且题目保证答案存在 ) 输出每个人手中的 牌的编号 . 解题 : 结构体存下牌的数值和编号,然后 sort 一下,从两边输出就好辣(因为答案保证存在). */ #include<cstdio> #include<cstring> #include<algorithm> #include<iost

CodeForces 1292C Xenon&#39;s Attack on the Gangs

Description 描述 给一个 $n$ 个点的树,要求你将 $0 \sim n - 2$ 不重不漏的放在这 $n - 1$ 条边上,求 $S = \sum\limits_{1 \le u < v \le n} \operatorname{mex}(u, v)$ 的最大值,$\operatorname{mex}(u, v)$ 表示 $<\! u \to v \!>$ 的路径上所经过的边权集合中最小的没出现的非负数. 输入 第一行一个正整数 $n$($2 \le n \le 3000$

Codeforces Round #614 (Div. 2) E. Xenon&#39;s Attack on the Gangs

On another floor of the A.R.C. Markland-N, the young man Simon "Xenon" Jackson, takes a break after finishing his project early (as always). Having a lot of free time, he decides to put on his legendary hacker "X" instinct and fight ag