QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#606190#5. 在线 O(1) 逆元Yoshinow2001100 ✓2498ms17184kbC++23564b2024-10-02 23:00:252024-11-05 22:04:21

Judging History

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

  • [2024-11-05 22:04:21]
  • 管理员手动重测本题所有提交记录
  • 测评结果:100
  • 用时:2498ms
  • 内存:17184kb
  • [2024-10-02 23:00:27]
  • 评测
  • 测评结果:100
  • 用时:2747ms
  • 内存:17588kb
  • [2024-10-02 23:00:25]
  • 提交

answer

#include<bits/stdc++.h>
#include "inv.h"
const int N=(1<<21)+5;
const int mod=998244353;
const int B=1024;
int pl[N],iv[N];
void init(int p){
	const int n=2*B*B;
	iv[1]=1;
	for(int i=2;i<=n;i++) iv[i]=1ll*(mod-iv[mod%i])*(mod/i)%mod;
	for(int i=1;i<=B;i++){
		int x=0;
		while(x<=B*B){
			long long w=1ll*x*B*i%mod;
			if(w<=B*B||w>=mod-B*B) pl[x]=i,x++;
			else x+=(mod-B*B-w+B*i-1)/(B*i);
		}
	}
}
int inv(int x){
	long long w=1ll*x*pl[x>>10]%mod;
	if(w<=2*B*B) return 1ll*iv[w]*pl[x/B]%mod;
	else return 1ll*(mod-iv[mod-w])*pl[x/B]%mod;
}

Details


Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 18ms
memory: 16704kb

Test #2:

score: 20
Accepted
time: 273ms
memory: 17184kb

Test #3:

score: 30
Accepted
time: 1259ms
memory: 16676kb

Test #4:

score: 20
Accepted
time: 1990ms
memory: 16196kb

Test #5:

score: 20
Accepted
time: 2498ms
memory: 16780kb