QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#134755#5. 在线 O(1) 逆元sserxhs100 ✓2611ms24812kbC++20971b2023-08-04 20:45:142024-11-05 21:51:12

Judging History

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

  • [2024-11-05 21:51:12]
  • 管理员手动重测本题所有提交记录
  • 测评结果:100
  • 用时:2611ms
  • 内存:24812kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-04 20:45:16]
  • 评测
  • 测评结果:100
  • 用时:2994ms
  • 内存:24732kb
  • [2023-08-04 20:45:14]
  • 提交

answer

#include "bits/stdc++.h"
using namespace std;
namespace online_inv
{
	typedef unsigned int ui;
	typedef unsigned long long ll;
	const ui p=998244353;
	const ui n=1010,m=n*n,N=m+2;
	int l[N],r[N];
	ui y[N];
	bool s[N];
	ui _inv[N*2],i,j,k;
	void init_inv()
	{
		assert(n*n*n>p);
		_inv[1]=1;
		for (i=2; i<m*2; i++)
		{
			j=p/i;
			_inv[i]=(ll)(p-j)*_inv[p-i*j]%p;
		}
		s[0]=y[0]=1;
		for (i=1; i<n; i++) for (j=i; j<n; j++) if (!s[k=i*m/j])
		{
			y[k]=j;
			s[k]=1;
		}
		l[0]=1;
		for (i=1; i<=m; i++) l[i]=s[i]?y[i]:l[i-1];
		r[m]=1;
		for (i=m-1; ~i; i--) r[i]=s[i]?y[i]:r[i+1];
		for (i=0; i<=m; i++) y[i]=min(l[i],r[i]);
	}
	inline ui inv(const ui &x)
	{
		assert(x&&x<p);
		if (x<m*2) return _inv[x];
		k=(ll)x*m/p;
		j=(ll)y[k]*x%p;
		return (j<m*2?_inv[j]:p-_inv[p-j])*(ll)y[k]%p;
	}
}
using online_inv::init_inv,online_inv::p;
void init(int p)
{
	init_inv();
}
int inv(int x)
{
	return online_inv::inv(x);
}

Details


Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 21ms
memory: 24812kb

Test #2:

score: 20
Accepted
time: 274ms
memory: 24704kb

Test #3:

score: 30
Accepted
time: 1337ms
memory: 24700kb

Test #4:

score: 20
Accepted
time: 2088ms
memory: 24616kb

Test #5:

score: 20
Accepted
time: 2611ms
memory: 24812kb