QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#479810#5. 在线 O(1) 逆元NOI_AK_ME#100 ✓1900ms19540kbC++23838b2024-07-15 20:58:002024-07-15 20:58:00

Judging History

你现在查看的是测评时间为 2024-07-15 20:58:00 的历史记录

  • [2024-11-05 22:00:43]
  • 管理员手动重测本题所有提交记录
  • 测评结果:100
  • 用时:2079ms
  • 内存:19556kb
  • [2024-07-15 20:58:00]
  • 评测
  • 测评结果:100
  • 用时:1900ms
  • 内存:19540kb
  • [2024-07-15 20:58:00]
  • 提交

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;
	for(unsigned i = 2;i ^ 3035136;++i)
		a[i] = 998244353 - (unsigned long long)(998244353 / i) * a[998244353 % i] % 998244353;
}

Details

Test #1:

score: 30
Accepted
time: 14ms
memory: 19536kb

Test #2:

score: 40
Accepted
time: 195ms
memory: 19540kb

Test #3:

score: 30
Accepted
time: 1900ms
memory: 19336kb