QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#68269 | #433. 抽卡 | Lenstar | 0 | 0ms | 0kb | C++14 | 5.9kb | 2022-12-15 15:44:40 | 2022-12-15 15:44:41 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define Re register
#define Mod 998244353
#define mkp(a,b) make_pair(a,b)
typedef pair<int, int> pii;
inline int read() {
int x = 0;
char ch = getchar();
while (!isdigit(ch))
ch = getchar();
while (isdigit(ch))
x = x * 10 + ch - '0', ch = getchar();
return x;
}
#define N 500010
int f[N], g[N], fac[N], inv[N], Inv[N];
inline int init(int n) {
fac[0] = fac[1] = inv[0] = inv[1] = Inv[0] = Inv[1] = 1;
for (int i = 2; i <= n; i++)
fac[i] = 1LL * fac[i - 1] * i % Mod;
for (int i = 2; i <= n; i++)
inv[i] = 1LL * (Mod - Mod / i) * inv[Mod % i] % Mod;
for (int i = 2; i <= n; i++)
Inv[i] = 1LL * Inv[i - 1] * inv[i] % Mod;
}
inline int C(int n, int m) {
if (n < m)
return 0;
return 1LL * fac[n] * Inv[m] % Mod * Inv[n - m] % Mod;
}
inline void Add(int &x, int y) {
x + y < Mod ? x += y : x += y - Mod;
}
inline vector<int> GetP(int n, int k) {
vector<int> vec(n + 1);
for (int i = 0; i <= n / (k + 1); i++) {
for (int j = 0; j <= i; j++) {
int tmp = 1LL * C(n - i * k, i) * C(i, j) % Mod;
Add(vec[i * k + j], (i - j) & 1 ? Mod - tmp : tmp);
}
}
// while (!vec.empty() && !vec.back()) vec.pop_back();
// for (int i=0;i<vec.size();i++) if (vec[i]) vec[i]=Mod-vec[i];
return vec;
}
inline vector<int> GetPoly(int n, int k) {
vector<int> v1 = GetP(n, k);
int siz1 = v1.size();
vector<int> v2 = GetP(n - k, k);
int siz2 = v2.size();
for (int i = 0; i < siz2; i++)
Add(v1[i + k], Mod - v2[i]);
while (!v1.empty() && !v1.back())
v1.pop_back();
// for (int i=0;i<v1.size();i++) if (v1[i]) v1[i]=Mod-v1[i];
// for (auto i:v1) printf("%d ",i); puts("");
return v1;
// vector<int> vec(n+2); ++n;
// for (Re int i=0;i*k<=n;i++)
// for (Re int j=0;j*(k+1)<=n;j++) {
// int tmp=1LL*C(i+j,i)*C(n-i*k-j*(k+1),i+j)%Mod;
// Add(vec[i*k+j*(k+1)],i&1?Mod-tmp:tmp);
// }
// while (!vec.empty() && !vec.back()) vec.pop_back();
// for (int i=0;i<vec.size();i++) if (vec[i]) vec[i]=Mod-vec[i];
// for (int i=0;i<vec.size();i++)
// printf("%d ",vec[i]);
// puts("");
// return vec;
}
inline int Pow(int a, int b, int p = Mod) {
int res = 1;
for (; b; b >>= 1, a = 1LL * a * a % p)
if (b & 1)
res = 1LL * res * a % p;
return res;
}
const int G = 3;
int A[N], B[N], rev[N];
inline void NTT(int *a, int len, int f) {
int k = 0;
while ((1 << k) < len)
k++;
for (int i = 0; i < len; i++) {
rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (k - 1));
if (i < rev[i])
swap(a[i], a[rev[i]]);
}
for (int l = 2; l <= len; l <<= 1) {
int m = l >> 1, w = Pow(G, (Mod - 1) / l);
if (f)
w = Pow(w, Mod - 2);
for (int i = 0; i < len; i += l) {
int wk = 1;
for (int j = 0; j < m; j++, wk = 1LL * wk * w % Mod) {
int p = a[i + j], q = 1LL * wk * a[i + j + m] % Mod;
a[i + j] = (p + q) % Mod, a[i + j + m] = (Mod + p - q) % Mod;
}
}
}
}
inline void DFT(int *a, int len) {
NTT(a, len, 0);
}
inline void IDFT(int *a, int len) {
NTT(a, len, 1);
int inv = Pow(len, Mod - 2);
for (int i = 0; i < len; i++)
a[i] = 1LL * a[i] * inv % Mod;
}
inline vector<int> Mul(vector<int> a, vector<int> b) {
int n = a.size(), m = b.size();
vector<int> ans(n + m - 1);
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
Add(ans[i + j], 1LL * a[i]*b[j] % Mod)/* ,printf("%d %d %d %d %d\n",i,j,1LL*a[i]*b[j]%Mod) */;
// for (auto i:ans) printf("%d ",i); puts("");
return ans;
// int n=a.size()+1,m=b.size()+1,len=1; while (len<n+m) len<<=1;
// for (int i=0;i<n-1;i++) A[i]=a[i]; for (int i=n-1;i<len;i++) A[i]=0;
// for (int i=0;i<m-1;i++) B[i]=b[i]; for (int i=m-1;i<len;i++) B[i]=0;
// DFT(A,len),DFT(B,len); for (int i=0;i<len;i++) A[i]=1LL*A[i]*B[i]%Mod; IDFT(A,len);
// vector<int> ans(len); for (int i=0;i<len;i++) ans[i]=A[i];
// while (!ans.empty() && !ans.back()) ans.pop_back(); return ans;
}
vector<vector<int>> vec;
inline vector<int> Merge() {
priority_queue<pii, vector<pii>, greater<pii>> heap;
for (int i = 0; i < vec.size(); i++)
heap.push(mkp(vec[i].size(), i));
while (!heap.empty()) {
pii vec1 = heap.top();
heap.pop();
if (heap.empty())
return vec[vec1.second];
pii vec2 = heap.top();
heap.pop();
// puts("Mul");
// for (int i=0;i<vec[vec1.second].size();i++) printf("%d ",vec[vec2.second][i]); puts("");
// for (int i=0;i<vec[vec2.second].size();i++) printf("%d ",vec[vec2.second][i]); puts("");
vec[vec1.second] = Mul(vec[vec1.second], vec[vec2.second]);
// puts("=");
// for (int i=0;i<vec[vec1.second].size();i++) printf("%d ",vec[vec1.second][i]); puts("");
heap.push(mkp(vec[vec1.second].size(), vec1.second));
}
}
int vis[N];
int main() {
int n = read(), k = read(), m = n << 1, cnt = 0;
init(m);
for (int i = 1; i <= n; i++)
g[i] = (g[i - 1] + 1LL * n * inv[i] % Mod) % Mod;
for (int i = 1; i <= n; i++)
vis[read()] = true;
for (int i = 1; i <= m; i++) {
if (vis[i]) {
++cnt;
continue;
}
if (cnt >= k)
vec.push_back(GetPoly(cnt, k));
cnt = 0;
}
vector<int> ans = Merge();
int res = 0; // puts("");
// for (int i=0;i<ans.size();i++) printf("%d ",ans[i]); puts("");
for (int i = 0; i < ans.size(); i++)
(res += 1LL * (Mod - ans[i]) * g[i] % Mod) %= Mod;
return printf("%d\n", res), 0;
}
詳細信息
Test #1:
score: 0
Runtime Error
input:
10 3 1 2 3 5 6 7 8 9 10 11
output:
result:
Test #2:
score: 0
Runtime Error
input:
500 499 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 10...
output:
result:
Test #3:
score: 0
Runtime Error
input:
500 13 397 284 276 435 348 557 14 561 516 352 125 56 240 337 417 37 2 281 414 307 210 336 232 382 224 122 58 133 137 393 488 92 469 238 48 453 241 533 492 424 260 213 487 571 33 178 97 158 135 575 292 331 478 118 121 11 85 552 460 219 415 272 293 479 481 304 254 55 212 351 230 164 472 422 7 28 19 39...
output:
result:
Test #4:
score: 0
Runtime Error
input:
500 9 464 333 321 508 405 641 14 645 599 412 147 69 279 394 488 40 2 328 486 359 243 393 270 444 261 145 71 158 162 458 568 111 547 278 59 529 280 617 571 496 302 247 567 658 35 209 115 183 160 665 343 386 556 139 144 11 103 637 539 254 487 318 344 557 558 356 293 68 246 408 268 189 549 494 7 30 20 ...
output:
result:
Test #5:
score: 0
Runtime Error
input:
500 30 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 ...
output:
result:
Test #6:
score: 0
Runtime Error
input:
5000 100 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100...
output:
result:
Test #7:
score: 0
Runtime Error
input:
5000 300 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100...
output:
result:
Test #8:
score: 0
Runtime Error
input:
200000 5 1 2 3 4 5 6 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 ...
output:
result:
Test #9:
score: 0
Runtime Error
input:
200000 2000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...
output:
result:
Test #10:
score: 0
Runtime Error
input:
200000 50 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 69 70 71 72 73 74 75 76 77 78 79 80 81 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 ...