QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#564519 | #5. 在线 O(1) 逆元 | caowenze | 100 ✓ | 2886ms | 30488kb | C++17 | 842b | 2024-09-15 08:49:25 | 2024-11-05 22:03:41 |
Judging History
answer
#include<bits/stdc++.h>
#include"inv.h"
#define ll long long
using namespace std;
const int N=(1<<21)+1,mod=998244353,M=1024;
int k,p[N<<1],*iv=p+N;
struct I{
int ml,dis;
}mp[N];
int inv(int w){
I d=mp[w>>10];
return (ll)iv[w*d.ml-d.dis]*(mod+d.ml)%mod;
}
void init(int rp){
k=mod/M;
int rlim=mod-k;
for(int i=1;i<=M;i++){
int cur=0,add=i*M;
for(int p=0;p<=k;){
if(cur<=k)mp[p].ml=i;
else if(cur>rlim)mp[p].ml=-i;
else{
int x=(rlim-cur)/add;
cur+=x*add,p+=x;
}
cur+=add,p++;
if(cur>=mod)cur-=mod;
}
}
int count=0;
for(int i=1;i<=k;i++)
if(mp[i].ml>0)mp[i].dis=(ll)mp[i].ml*i*M/mod*mod,++count;
else mp[i].dis=(ll)mp[i].ml*i*M/mod*mod-mod,++count;
iv[1]=1;
for(int i=2;i<=N-1;i++)iv[i]=(ll)iv[mod%i]*(mod-mod/i)%mod;
for(int i=1;i<=N-1;i++)iv[-i]=mod-iv[i];
}
Details
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 21ms
memory: 30372kb
Test #2:
score: 20
Accepted
time: 323ms
memory: 30416kb
Test #3:
score: 30
Accepted
time: 1587ms
memory: 28380kb
Test #4:
score: 20
Accepted
time: 2421ms
memory: 30316kb
Test #5:
score: 20
Accepted
time: 2886ms
memory: 30488kb