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

On the picture below show the state of the board after put each of the three rooks. The cells which painted with grey color is not under the attack.

题意是放棋子,没有与任何棋子处于同一行的格子数为多少。
观察样例,可以发现一个事实,剩下的格子如果还存在的话,一定能够成一个矩形,我们从这个角度去考虑;
看样例,放了第一个棋子,长宽都小了一,那是不是每放一个棋子,长宽均减一呢,并不是这样的,第二个只是宽度减一;
从这,我们可以看出后放的棋子只有不与先前的棋子同列,宽才减一;不与先前的棋子同行,长才减一;
可用 v 数组记录前面出现过的棋子的横纵坐标。
两个注意点:答案超 int ;长宽等于0就直接输出0.
#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
#define INF 0x3f3f3f3f
typedef long long LL;
int x[100005],y[100005];
bool v1[100005],v2[100005];
int main()
{
    int m;
    __int64 n,p,q;
    while(~scanf("%I64d%d",&n,&m)){
    p=q=n-1;
    for(int i=0;i<m;i++){
        scanf("%d%d",&x[i],&y[i]);
    }
    memset(v1,false,sizeof(v1));
    memset(v2,false,sizeof(v2));
    for(int t=0;t<m;t++){
        if(t==0){
            v1[x[0]]=true;
            v2[y[0]]=true;
            printf("%I64d",p*q);
        }else{
            if(!p||!q){
                printf(" 0");
            }else{
                if(!v1[x[t]]){
                    p--;
                }
                if(!v2[y[t]]){
                    q--;
                }
                v1[x[t]]=v2[y[t]]=true;
                printf(" %I64d",p*q);
            }
        }
    }
    printf("\n");
    }
    return 0;
}



内容概要:本研究聚焦于“绿电直连型电氢氨园区”的优化运行,提出一种直接利用绿色电力驱动制氢与合成氨的综合能源系统架构。通过构建包含风/光发电、电解水制氢、氢气储存、合成氨反应及电能直供等关键环节的系统模型,研究旨在实现能源的高效转化与梯级利用,降低对外部电网依赖,提升园区能源自洽率与经济性。研究综合运用Matlab与Python工具进行建模与仿真,结合实际气象与负荷数据,对系统在不同工况下的运行策略、能量流动、设备容量配置及经济技术指标进行深入分析与优化,并形成完整的Word论文文档,为新型零碳产业园区的规划与建设提供了理论依据和技术支撑。; 适合人群:具备新能源、电力系统、化工或综合能源系统背景的科研人员,以及从事园区规划、能源管理、低碳技术开发的工程技术人员。; 使用场景及目标:①研究绿电如何高效耦合至化工生产流程,实现“电-氢-氨”多能互补;②掌握综合能源系统(IES)的建模、仿真与优化方法,特别是多时间尺度下的运行调度策略;③为撰写高水平学术论文或完成相关课题研究积累数据、代码与写作模板。; 阅读建议:此资源包含代码、数据和完整论文,建议使用者先通读Word论文以理解整体框架与理论基础,再结合Matlab/Python代码进行复现与调试,最后可基于提供的数据和模型进行二次开发,以深化对绿电综合利用技术的理解。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值