Educational Codeforces Round 65 (Rated for Div. 2)C. News Distribution(模拟,计算的时候去重)

这道题目明显和出现4次的数和出现2次的数的个数有关系,只需要在每次更新之后维护这两个信息即可,我们在算出现2次的数的个数时其实会把出现4次的数的个数会把出现2次的数的个数+2,在判断时需要考虑这一点。也就是 c n t 2 > = 4 & & c n t 4 > = 1 cnt2>=4\&\&cnt4>=1 cnt2>=4&&cnt4>=1时才有解

#include <bits/stdc++.h> 
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(int i = (a); i >= (b); --i)
#define ls p<<1
#define rs p<<1|1
#define PII pair<int, int>
#define ll long long
#define ull unsigned long long
#define db double
#define endl '\n'
#define debug(a) cout<<#a<<"="<<a<<endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define INF 0x3f3f3f3f 
#define x first
#define y second
using namespace std;

const int N=1e5+10,mod=1e9+7;
int a[N],cnt[N];


void solve()
{
	int n,f=0,t=0;
	cin>>n;
	rep(i,1,n)
	{
		cin>>a[i];
		cnt[a[i]]++;
		if(cnt[a[i]]%4==0)	f++;
		if(cnt[a[i]]%2==0)	t++;
	}
	int q;cin>>q;
	while(q--)
	{
		char op;int k;cin>>op>>k;
		if(op=='+')
		{
			cnt[k]++;
			if(cnt[k]%4==0)	f++;
			if(cnt[k]%2==0)	t++;
		}
		if(op=='-')
		{
			if(cnt[k]%4==0)	f--;
			if(cnt[k]%2==0)	t--;
			cnt[k]--;
		}
		if(f>=1&&t>=4)	cout<<"YES"<<endl;
		else	cout<<"NO"<<endl;
	} 
}

int main()
{
	IOS	
//  	freopen("1.in", "r", stdin);
  	int t;
//	cin>>t;
//	while(t--)
	solve();
	return 0;
}
  • 8
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值