Codeforces Round #364 (Div. 2) B. Cells Not Under Attack 标记数组

本文介绍了一种通过标记横纵坐标来更新二维数组中剩余可用位置数量的算法。该算法适用于跟踪已分配资源的情况,例如在网格布局或资源分配问题中。通过每次迭代更新两个一维数组来记录被占用的位置,进而计算剩余可用位置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

标记横纵坐标  数组标记 

AC代码:

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<string>
using namespace std;
#define N 6000
#define INF 1e9+5
long long a[1000100];
long long b[1000100];
long long ans[1000100];
long long n, m, x, y;
int main()
{
	long long i, j;
	scanf("%I64d%I64d", &n, &m);
	long long x = n, y = n;
	for (i = 1; i <= m; i++)
	{
		long long x1, y1;
		scanf("%I64d%I64d", &x1, &y1);
		if (a[x1] == 0)
		{
			x--;
			a[x1] = 1;
		}
		if (b[y1] == 0)
		{
			y--;
			b[y1] = 1;
		}
		ans[i] = x*y;
	}
	for (i = 1; i <= m; i++)
	{
		if (i == 1) printf("%I64d", ans[i]);
		else       printf(" %I64d", ans[i]);
	}
	printf("\n");
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值