QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#863512#5. 在线 O(1) 逆元tanfuxuan100 ✓1914ms92580kbC++14869b2025-01-19 18:25:502025-01-19 18:25:50

Judging History

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

  • [2025-01-19 18:25:50]
  • 评测
  • 测评结果:100
  • 用时:1914ms
  • 内存:92580kb
  • [2025-01-19 18:25:50]
  • 提交

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];
}

详细


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