QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#24689 | #5. 在线 O(1) 逆元 | skip2004 | 100 ✓ | 4599ms | 19680kb | C++20 | 827b | 2022-04-02 11:07:35 | 2024-11-05 21:43:31 |
Judging History
你现在查看的是测评时间为 2024-11-05 21:43:31 的历史记录
- [2023-08-10 23:21:45]
- System Update: QOJ starts to keep a history of the judgings of all the submissions.
- [2022-04-02 11:07:35]
- 提交
answer
#include<cmath>
#include<functional>
#include"inv.h"
const int mod = 998244353;
const int mod2 = 974849;
const int w = sqrt(mod2);
const int limit = 3 * (w + 1) * 1024;
int djq[limit], arr[mod2];
using u64 = unsigned long long;
int inv(int x) {
const int p = (u64) x * arr[x >> 10] % mod;
return (u64) arr[x >> 10] * (p < limit ? djq[p] : mod - djq[mod - p]) % mod;
}
void init(int) {
for(int i = w;i >= 1;--i) {
std::function<int(int)> getinv = [&](int x) {
return x == 1 ? 1 : mod2 - u64(mod2 / x) * getinv(mod2 % x) % mod2;
};
int inv = getinv(i);
for(int j = 1;j <= w;++j) {
arr[(u64) j * inv % mod2] = i;
arr[mod2 - (u64) j * inv % mod2] = mod - i;
}
}
arr[0] = 1, djq[1] = 1;
for(int i = 2;i < limit;++i) {
djq[i] = mod - u64(mod / i) * djq[mod % i] % mod;
}
}
Details
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 14ms
memory: 19376kb
Test #2:
score: 20
Accepted
time: 212ms
memory: 19448kb
Test #3:
score: 30
Accepted
time: 2554ms
memory: 19680kb
Test #4:
score: 20
Accepted
time: 3025ms
memory: 19448kb
Test #5:
score: 20
Accepted
time: 4599ms
memory: 19420kb