QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#480316#5. 在线 O(1) 逆元NOI_AK_ME#100 ✓2726ms19544kbC++23859b2024-07-16 13:30:042024-11-05 22:01:36

Judging History

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

  • [2024-11-05 22:01:36]
  • 管理员手动重测本题所有提交记录
  • 测评结果:100
  • 用时:2726ms
  • 内存:19544kb
  • [2024-07-16 13:30:04]
  • 评测
  • 测评结果:100
  • 用时:1892ms
  • 内存:19552kb
  • [2024-07-16 13:30:04]
  • 提交

answer

#pragma once
#pragma GCC optimize("Ofast, unroll-loops")
#include "inv.h"
unsigned a[3035136], g[974849];
int inv(int x) {
	const unsigned p = (unsigned long long) x * g[x >> 10] % 998244353;
	return (unsigned long long) g[x >> 10] * (p < 3035136 ? a[p] : 998244353 - a[998244353 - p]) % 998244353;
}
unsigned getinv(unsigned x) {
    return x == 1 ? 1 : 974849 - (unsigned long long)(974849 / x) * getinv(974849 % x) % 974849;
}
void init(int) {
	for (unsigned i = 987; i; --i) {
		unsigned inv = getinv(i);
		for (unsigned j = 1; j ^ 988;++j) {
			g[(unsigned long long) j * inv % 974849] = i;
			g[974849 - (unsigned long long) j * inv % 974849] = 998244353 - i;
		}
	}
	g[0] = a[1] = 1;
	#pragma unroll
	for (unsigned i = 2; i ^ 3035136;++i)
		a[i] = 998244353 - (unsigned long long)(998244353 / i) * a[998244353 % i] % 998244353;
}

Details


Pretests


Final Tests

Test #1:

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

Test #2:

score: 20
Accepted
time: 370ms
memory: 19544kb

Test #3:

score: 30
Accepted
time: 1601ms
memory: 19472kb

Test #4:

score: 20
Accepted
time: 2356ms
memory: 19356kb

Test #5:

score: 20
Accepted
time: 2726ms
memory: 19544kb