QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#479764 | #5. 在线 O(1) 逆元 | BlackPanda | 100 ✓ | 1686ms | 24364kb | C++14 | 1.0kb | 2024-07-15 20:46:53 | 2024-07-15 20:46:53 |
Judging History
answer
#include "inv.h"
#include <bits/stdc++.h>
using i64 = long long;
constexpr int P = 998244353;
namespace Inversion {
static constexpr int B = (1 << 10), T = (1 << 20);
int f[T + 5], p[T + 5], buf[T * 3 + 5];
int *I = buf + T;
void init() {
for (int u = 1; u <= B; u++) {
int s = 0, d = (u << 10);
for (int a = 1; a <= T; a++) {
if ((s += d) >= P) s -= P;
if (s <= T) {
if (!f[a]) f[a] = u, p[a] = s;
continue;
}
if (s >= P - T) {
if (!f[a]) f[a] = u, p[a] = s - P;
continue;
}
int t = (P - T - s - 1) / d;
s += t * d, a += t;
}
}
I[1] = f[0] = 1;
for (int i = 2; i <= (T << 1); i++) I[i] = 1ll * (P - P / i) * I[P % i] % P;
for (int i = -1; i >= -T; i--) I[i] = P - I[-i];
}
int inv(int x) { return 1ll * I[p[x >> 10] + (x & 1023) * f[x >> 10]] * f[x >> 10] % P; }
};
void init(int p) {
Inversion::init();
}
int inv(int x) {
return Inversion::inv(x);
}
详细
Test #1:
score: 30
Accepted
time: 15ms
memory: 24292kb
Test #2:
score: 40
Accepted
time: 188ms
memory: 24364kb
Test #3:
score: 30
Accepted
time: 1686ms
memory: 24232kb