codeforces 1648B
B. Integral Array
思路:
枚举因子,\([x/y]=z,则y*z<=x<=y*z+y-1\)
代码:
#include <bits/stdc++.h>
#define int long long
int _ = 0, Case = 1;
using namespace std;
#define all(v) begin(v),end(v)
#define nline '\n'
const int N = 1000010;
int cnt[N];
int a[N];
int s[N];
void solve(int Case) {
int n, c;
cin >> n >> c;
for (int i = 1; i <= c; i++) cnt[i] = 0, s[i] = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
cnt[a[i]]++;
}
sort(a + 1, a + 1 + n);
for (int i = 1; i <= c; i++) {
s[i] = s[i - 1] + cnt[i];
}
for (int i = 1; i <= c; i++) {
if (!cnt[i]) continue;
int x = i;
int sum = 0;
for (int j = x; j <= c; j += x) {
int t = j / x;
if (!cnt[t]) continue;
int l = j, r = min(c, j + x - 1);
sum += s[r] - s[l - 1];
}
if (sum != (s[c] - s[x - 1])) {
cout << "NO" << nline;
return;
}
}
cout << "YES" << nline;
}
signed main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
for (cin >> _, Case = 1; Case <= _; Case++)
solve(Case);
return 0;
}