Codeforces Round # 615 (Div. 3) D. MEX maximizing (thinking good title)

Topic Link
Here Insert Picture Description
Here Insert Picture Description
meaning of the questions: given q times and ask x, Always ask will add a number to an array (array initially empty), you can each + x and -x operation, ask for any number of array your current array smallest integer not appear.
Ideas: Even E and F are made out actually stuck in this problem, I feel like thinking and observation skills can not. . . .
In fact, every time you can add unlimited X minus X should not think the result will only affect the modulus of x, find a space on the line.

#include<bits/stdc++.h>
using namespace std;
const int maxn=4e5+10;
int a[maxn];
int main()
{
	int q,x,t,ans=0;
	scanf("%d%d",&q,&x);
	while(q--)
	{
		scanf("%d",&t);
		a[t%x]++;
		while(a[ans%x])
		a[ans%x]--,ans++;
		printf("%d\n",ans);
 	} 
}
Published 70 original articles · won praise 0 · Views 2430

Guess you like

Origin blog.csdn.net/qq_42479630/article/details/104232998