QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#153089#5. 在线 O(1) 逆元YeahPotato100 ✓1950ms24368kbC++14737b2023-08-29 11:23:272024-11-05 21:51:31

Judging History

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

  • [2024-11-05 21:51:31]
  • 管理员手动重测本题所有提交记录
  • 测评结果:100
  • 用时:1950ms
  • 内存:24368kb
  • [2023-08-29 11:23:27]
  • 评测
  • 测评结果:100
  • 用时:2419ms
  • 内存:24236kb
  • [2023-08-29 11:23:27]
  • 提交

answer

#include "inv.h"
#include <bits/stdc++.h>
using namespace std;
const int B = 1 << 10, T = 1 << 20, P = 998244353;
int f[T+1], p[T+1], buf[T*3+3], * I = buf + T;
void init(int) {
	for (int i=1; i<=B; i++) {
		int s = 0, d = i << 10;
		for (int j=1; j<=T; j++) {
			if ((s += d) >= P) s -= P;
			if (s <= T) {
				if (! f[j]) f[j] = i, p[j] = s;
			} else if (s >= P - T) {
				if (! f[j]) f[j] = i, p[j] = s - P;
			} else {
				int t = (P - T - s - 1) / d;
				s += t * d, j += t;
			}
		}
	}
	I[1] = f[0] = 1;
	for (int i=2; i<=T<<1; i++)
		I[i] = 1ll * (P - P / i) * I[P%i] % P;
	for (int i=-1; i>=-T; i--)
		I[i] = P - I[-i];
}
int inv(int x) {
	return 1ll * I[p[x>>10]+(x&1023)*f[x>>10]] * f[x>>10] % P;
}

Details


Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 20ms
memory: 24180kb

Test #2:

score: 20
Accepted
time: 210ms
memory: 24368kb

Test #3:

score: 30
Accepted
time: 984ms
memory: 24184kb

Test #4:

score: 20
Accepted
time: 1559ms
memory: 24264kb

Test #5:

score: 20
Accepted
time: 1950ms
memory: 24264kb