题意
一个游戏,一共有q个回合,初始你有一个空数组,每个回合向你的数组塞一个数,你可以对数组中的数加或减X的任意倍数,你的任务是在每回合找到数组内不存在的最小整数,并且通过操作使最小整数最大
思路
我们可以从零枚举这个最小整数,判断是否数组中存在可以变为这个数的数,如果不存在这个数就是我们要找的最小整数。可以知道对于a, b两个数,只要满足(a - b) % x == 0, 就可以通过对a加或者减x的倍数把a变成b。
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10;
int a[N], ans;
int main(){
int q, x;
cin >> q >> x;
while (q --){
int k;
cin >> k;
a[k % x] ++;
while (a[ans % x]) a[ans % x] --, ans ++;
cout << ans << endl;
}
}