QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#16078 | #5. 在线 O(1) 逆元 | Prean | 100 ✓ | 3941ms | 23632kb | C++ | 1.0kb | 2021-11-17 18:31:00 | 2024-11-05 21:46:17 |
Judging History
你现在查看的是最新测评结果
- [2023-08-10 23:21:45]
- System Update: QOJ starts to keep a history of the judgings of all the submissions.
- [2021-11-17 18:31:00]
- 提交
answer
#include "inv.h"
typedef unsigned ui;
typedef unsigned long long ull;
const ui mod=998244353,M1=1000,M2=M1*M1;
const double invM1=1./M1+1e-15,INV=1.*M2/mod+1e-15;
ui T,len,fra[M2+5],Inv[M2+5],sum[M2+5];
ui q[M2+5];ull p[M2+5];
inline ull abs(const ull&a){
return a>>63?-a:a;
}
inline void Init(){
ui i,j,x;
for(i=1;i^M1;++i){
const double&INV=1./i+1e-15;
for(j=0;j^i;++j)if(!sum[x=1ull*j*M2*INV])sum[x]=1,fra[x]=M1*i+j;
}
for(i=0;i<=M2;++i){
if(sum[i])++len,q[len]=fra[i]*invM1,p[len]=1ull*(fra[i]-q[len]*M1)*mod;
if(i)sum[i]+=sum[i-1];Inv[i]=i>1?1ull*(mod-mod/i)*Inv[mod%i]%mod:i;
}
}
inline ui Qry(const ui&a){
static ui q,k;static ull t;
if(a<=M2)return Inv[a];if(mod-a<=M2)return mod-Inv[mod-a];k=sum[ui(a*INV)];
if(k<=len){
q=::q[k];t=1ull*a*q-p[k];
if(abs(t)<=M2)return 1ull*q*(t>>63?mod-Inv[-t]:Inv[t])%mod;
}
if(++k<=len){
q=::q[k];t=1ull*a*q-p[k];
if(abs(t)<=M2)return 1ull*q*(t>>63?mod-Inv[-t]:Inv[t])%mod;
}
return-1;
}
void init(int p){
Init();
}
int inv(int x){
return Qry(x);
}
Details
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 18ms
memory: 22364kb
Test #2:
score: 20
Accepted
time: 382ms
memory: 21160kb
Test #3:
score: 30
Accepted
time: 1858ms
memory: 22328kb
Test #4:
score: 20
Accepted
time: 3040ms
memory: 21332kb
Test #5:
score: 20
Accepted
time: 3941ms
memory: 23632kb