QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#480316 | #5. 在线 O(1) 逆元 | NOI_AK_ME# | 100 ✓ | 2726ms | 19544kb | C++23 | 859b | 2024-07-16 13:30:04 | 2024-11-05 22:01:36 |
Judging History
answer
#pragma once
#pragma GCC optimize("Ofast, unroll-loops")
#include "inv.h"
unsigned a[3035136], g[974849];
int inv(int x) {
const unsigned p = (unsigned long long) x * g[x >> 10] % 998244353;
return (unsigned long long) g[x >> 10] * (p < 3035136 ? a[p] : 998244353 - a[998244353 - p]) % 998244353;
}
unsigned getinv(unsigned x) {
return x == 1 ? 1 : 974849 - (unsigned long long)(974849 / x) * getinv(974849 % x) % 974849;
}
void init(int) {
for (unsigned i = 987; i; --i) {
unsigned inv = getinv(i);
for (unsigned j = 1; j ^ 988;++j) {
g[(unsigned long long) j * inv % 974849] = i;
g[974849 - (unsigned long long) j * inv % 974849] = 998244353 - i;
}
}
g[0] = a[1] = 1;
#pragma unroll
for (unsigned i = 2; i ^ 3035136;++i)
a[i] = 998244353 - (unsigned long long)(998244353 / i) * a[998244353 % i] % 998244353;
}
Details
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 18ms
memory: 19528kb
Test #2:
score: 20
Accepted
time: 370ms
memory: 19544kb
Test #3:
score: 30
Accepted
time: 1601ms
memory: 19472kb
Test #4:
score: 20
Accepted
time: 2356ms
memory: 19356kb
Test #5:
score: 20
Accepted
time: 2726ms
memory: 19544kb