QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#123819#5. 在线 O(1) 逆元NOI_AK_ME#100 ✓2428ms19176kbC++14796b2023-07-13 18:28:122023-07-13 18:28:16

Judging History

你现在查看的是测评时间为 2023-07-13 18:28:16 的历史记录

  • [2024-11-05 21:50:50]
  • 管理员手动重测本题所有提交记录
  • 测评结果:100
  • 用时:2622ms
  • 内存:19548kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-13 18:28:16]
  • 评测
  • 测评结果:100
  • 用时:2428ms
  • 内存:19176kb
  • [2023-07-13 18:28:12]
  • 提交

answer

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

Details

Test #1:

score: 30
Accepted
time: 12ms
memory: 19064kb

Test #2:

score: 40
Accepted
time: 252ms
memory: 19176kb

Test #3:

score: 30
Accepted
time: 2428ms
memory: 19064kb