QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#499438 | #5. 在线 O(1) 逆元 | lonelywolf | 100 ✓ | 1808ms | 24368kb | C++23 | 1.1kb | 2024-07-31 14:14:13 | 2024-11-05 22:02:43 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
struct 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;
int mod;
Inversion(int mod_) {
init(mod_);
}
void init(int mod_) {
mod = mod_;
for (int u = 1; u <= B; u++) {
int s = 0, d = (u << 10);
for (int a = 1; a <= T; a++) {
if ((s += d) >= mod) s -= mod;
if (s <= T) {
if (!f[a]) f[a] = u, p[a] = s;
continue;
}
if (s >= mod - T) {
if (!f[a]) f[a] = u, p[a] = s - mod;
continue;
}
int t = (mod - 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 * (mod - mod / i) * I[mod % i] % mod;
for (int i = -1; i >= -T; i--) I[i] = mod - I[-i];
}
int inv(int x) { return 1ll * I[p[x >> 10] + (x & 1023) * f[x >> 10]] * f[x >> 10] % mod; }
};
Inversion inver(998244353);
void init(int p) {
}
int inv(int x) {
return inver.inv(x);
}
详细
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 21ms
memory: 24264kb
Test #2:
score: 20
Accepted
time: 204ms
memory: 24368kb
Test #3:
score: 30
Accepted
time: 926ms
memory: 24264kb
Test #4:
score: 20
Accepted
time: 1445ms
memory: 24188kb
Test #5:
score: 20
Accepted
time: 1808ms
memory: 24368kb