比赛入口
D MEX maximizing
做法:题意是可以让数组里的一个数+x或者-x,找到最小的没有出现过的数字。做法就是…竟然是对x取模!用一个ans维护答案,如果当前ans%x没有出现过或者以前用完了,那么这时就输出ans,妙啊妙啊
代码:
#include<bits/stdc++.h>
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
using namespace std;
typedef long long LL;
typedef pair<LL, int> pli;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<double, double> pdd;
typedef map<char, int> mci;
typedef map<string, int> msi;
template<class T>
void read(T &res) {
int f = 1; res = 0;
char c = getchar();
while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); }
while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); }
res *= f;
}
const int N = 4e5+5;
int cnt[N];
int main() {
int q, x;
read(q); read(x);
int y;
int cur = 0, ans = 0;
for(int i = 0; i < q; ++i) {
read(y);
cnt[y%x]++;
while(cnt[ans%x]) {
cnt[ans%x]--;
ans++;
}
printf("%d\n", ans);
}
return 0;
}
后面两题没咋看懂…咕咕咕…