QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#479883 | #5. 在线 O(1) 逆元 | goj_bot1 | 100 ✓ | 1720ms | 24372kb | C++14 | 1.0kb | 2024-07-15 21:31:36 | 2024-11-05 22:00:44 |
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);
}
Details
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 17ms
memory: 24324kb
Test #2:
score: 20
Accepted
time: 186ms
memory: 24356kb
Test #3:
score: 30
Accepted
time: 886ms
memory: 24372kb
Test #4:
score: 20
Accepted
time: 1401ms
memory: 24360kb
Test #5:
score: 20
Accepted
time: 1720ms
memory: 24232kb