QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#106159 | #5. 在线 O(1) 逆元 | zhoukangyang | 100 ✓ | 1573ms | 30500kb | C++17 | 1.2kb | 2023-05-16 19:02:43 | 2024-11-05 21:50:04 |
Judging History
answer
#include<bits/stdc++.h>
#include "inv.h"
#define L(i, j, k) for(int i = (j); i <= (k); ++i)
#define R(i, j, k) for(int i = (j); i >= (k); --i)
#define ll long long
#define vi vector < int >
#define sz(a) ((int) (a).size())
#define ll long long
#define ull unsigned long long
#define me(a, x) memset(a, x, sizeof(a))
#define eb emplace_back
using namespace std;
const int B = 1024, mod = 998244353, N = (1 << 21) + 1;
int K, pool[N * 2], *iv = pool + N;
struct M {
int ml, dis;
} mp[N];
int inv(int w) {
M d = mp[w >> 10];
return (ull) iv[w * d.ml - d.dis] * (mod + d.ml) % mod;
}
void init(int rp) {
K = mod / B;
int Rlim = mod - K;
L(fb, 1, B) {
int cur = 0, Add = fb * B;
for(int p = 0; p <= K; ) {
if(cur <= K) mp[p].ml = fb;
else if(cur > Rlim) mp[p].ml = -fb;
else {
int A = (Rlim - cur) / Add;
cur += A * Add, p += A;
}
cur += Add, ++p;
if(cur >= mod) cur -= mod;
}
}
int count = 0;
L(i, 1, K)
if(mp[i].ml > 0) mp[i].dis = (ll) mp[i].ml * i * B / mod * mod, ++count;
else mp[i].dis = (ll) mp[i].ml * i * B / mod * mod - mod, ++count;
iv[1] = 1;
L(i, 2, N - 1) iv[i] = (ll) iv[mod % i] * (mod - mod / i) % mod;
L(i, 1, N - 1) iv[-i] = mod - iv[i];
}
Details
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 11ms
memory: 30444kb
Test #2:
score: 20
Accepted
time: 174ms
memory: 30340kb
Test #3:
score: 30
Accepted
time: 803ms
memory: 30452kb
Test #4:
score: 20
Accepted
time: 1272ms
memory: 30500kb
Test #5:
score: 20
Accepted
time: 1573ms
memory: 30496kb