Codeforces Round #662 (Div. 2) B-Thinking Question

Topic link
Insert picture description here

Title

First, provide the length of n planks. There are two operations in the process:
1. Add a plank of length x
2. Delete a plank of length x.
After each operation, ask whether the existing planks can form a square And a rectangle (this rectangle can also be a square)

Ideas

You can use an array to record the number of boards of each length and the number corresponding to this number of boards, and then use the number to determine whether the condition can be met after each change.

Code

#include<map>
#include<stack>
#include<queue>
#include<string>
#include<math.h>
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=1e6+5;
const int inf=0x3f3f3f3f;
const int minn=0xc0c0c0c0;
char c;
int a,n,q,x,ans,cnt,num[maxn],sum[maxn];
bool cmp(int a,int b)
{
    
    
	return a>b;
}
int main()
{
    
    
	cin>>n;
	for(int i=1;i<=n;i++)
	{
    
    
		cin>>a;//初始木板
		num[a]++;
		sum[num[a]]++;
	}
	cin>>q;
	while(q--)
	{
    
    
		bool flag=0;
		cin>>c>>x;
		if(c=='+')
		{
    
    
			num[x]++;
			sum[num[x]]++;
		}
		else
		{
    
    
			sum[num[x]]--;
			num[x]--;
		}
		if(sum[8]>=1||sum[4]>=2||(sum[2]>=3&&sum[4]>=1)||(sum[2]>=2&&sum[6]>=1))
			flag=1;//由于有数量为4或6的木板时,其在数量为2对应的木板中必然已经记数,所以需要个数比需要的多一个 
		if(flag)
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
	}
	return 0;
}

Guess you like

Origin blog.csdn.net/WTMDNM_/article/details/108677970