跳到正文

题解

P15196 [SWERC 2018] City of Lights 题解

mystic_clouds约 1 分钟
原文
文章信息与版本

文章信息

发布
2025年9月13日
收录
2025年12月12日
更新
2026年11月8日
篇幅
约 1 分钟
获赞
1
题目
P15196

版本

  1. v2当前
  2. v1

模拟开关过程,开一盏灯则熄灭数减一,否则加一,累加每次操作后的最大值即可。

AC Code
C++
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
using namespace std;
ll n,k,ans,cnt=0;
bool a[1000010];
class cla
{

};
struct str
{

};
namespace funtion
{
	void FSIO()
	{
		ios::sync_with_stdio(0);
		cin.tie(0);
		cout.tie(0);
		return;
	}
};
using namespace funtion;
int main()
{
	FSIO();
	cin>>n>>k;
	for(int i=1;i<=k;i++)
	{
		ll x,y;
		cin>>x;
		y=x;
		while(y<=n)
		{
			if(a[y]==1)
			{
				a[y]=0;
				cnt--;
			}
			else
			{
				a[y]=1;
				cnt++;
			}
			y+=x;
		}
		ans=max(ans,cnt);
	}
	cout<<ans;
	return 0;
}
原文