QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#564519#5. 在线 O(1) 逆元caowenze100 ✓2886ms30488kbC++17842b2024-09-15 08:49:252024-11-05 22:03:41

Judging History

你现在查看的是最新测评结果

  • [2024-11-05 22:03:41]
  • 管理员手动重测本题所有提交记录
  • 测评结果:100
  • 用时:2886ms
  • 内存:30488kb
  • [2024-09-15 08:49:25]
  • 评测
  • 测评结果:100
  • 用时:1791ms
  • 内存:30540kb
  • [2024-09-15 08:49:25]
  • 提交

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