QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#863512 | #5. 在线 O(1) 逆元 | tanfuxuan | 100 ✓ | 1914ms | 92580kb | C++14 | 869b | 2025-01-19 18:25:50 | 2025-01-19 18:25:50 |
Judging History
answer
#include<bits/stdc++.h>
#include"inv.h"
const int N=1e7,MOD=998244353;
int pool[N*2],*iv=pool+N;
std::pair<int,int> mp[N];
using ll=long long;
int inv(int w){
auto d=mp[w>>10];
return (ll)iv[w*d.first-d.second]*(MOD+d.first)%MOD;
}
void init(int _){
const int B=1024;
int K=MOD/B;
int Rlim=MOD-K;
for(int fb=1;fb<=B;fb++){
int cur=0,Add=fb*B;
for(int p=0;p<=K;){
if(cur<=K) mp[p].first=fb;
else if(cur>Rlim) mp[p].first=-fb;
else{
int A=(Rlim-cur)/Add;
cur+=A*Add,p+=A;
}
cur+=Add,++p;
if(cur>=MOD) cur-=MOD;
}
}
int count=0;
for(int i=1;i<=K;i++){
if(mp[i].first>0) mp[i].second=(ll)mp[i].first*i*B/MOD*MOD,++count;
else mp[i].second=(ll)mp[i].first*i*B/MOD*MOD-MOD,++count;
}
iv[1]=1;
for(int i=2;i<N;i++) iv[i]=(ll)iv[MOD%i]*(MOD-MOD/i)%MOD;
for(int i=1;i<N;i++) iv[-i]=MOD-iv[i];
}
Details
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 63ms
memory: 92328kb
Test #2:
score: 20
Accepted
time: 243ms
memory: 92572kb
Test #3:
score: 30
Accepted
time: 952ms
memory: 92580kb
Test #4:
score: 20
Accepted
time: 1502ms
memory: 92500kb
Test #5:
score: 20
Accepted
time: 1914ms
memory: 92576kb