1294D 1600
(最近不知道为啥思维下滑很严重)
题意:给你q组询问,和操作数x,你能对这个询问+n操作数或者-n操作数,问你每一次询问过后,最小的数是多少
思路:贪心,首先对于每一组询问都对于x取于,即这个询问能得到的最小的数是多少,然后对这个0~x-1进行标记,或者说更新,即对x取余之后这个数最小为多少,这里是本题最主要的贪心思想,标程跑了2000ms多
代码如下
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define int ll
typedef pair<int, int> pii;
#define rep(i, a, n) for(int i = a; i <= n; i++)
#define per(i, a, n) for(int i = n; i >= a; i--)
#define IOS std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define fopen freopen("file.in","r",stdin);freopen("file.out","w",stdout);
#define fclose fclose(stdin);fclose(stdout);
const int inf = 1e9;
const ll onf = 1e18;
const int maxn = 8e5+10;
inline int read(){
int x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=(x<<3)+(x<<1)+ch-48;ch=getchar();}
return x*f;
}
unordered_map<int, int> vis;
unordered_map<int, int> m;
signed main(){
int n = read(), k = read();
int pos = 0;
rep(i,1,n){
int x = read();
int tmp = x%k;
if(m.count(tmp)) x = m[tmp]+k;
else x = tmp;
m[tmp] = x;
vis[x] = 1;
// printf("%d ", x);
while(vis.count(pos)) pos++;
printf("%lld\n", pos);
}
return 0;
}