QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#214134#5. 在线 O(1) 逆元ucup-team1209100 ✓4642ms19676kbC++20842b2023-10-14 17:26:272024-11-05 21:53:38

Judging History

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

  • [2024-11-05 21:53:38]
  • 管理员手动重测本题所有提交记录
  • 测评结果:100
  • 用时:4642ms
  • 内存:19676kb
  • [2023-10-14 17:26:28]
  • 评测
  • 测评结果:100
  • 用时:2749ms
  • 内存:19288kb
  • [2023-10-14 17:26:27]
  • 提交

answer

#include<bits/stdc++.h>
#include"inv.h"
using std::cin;
using std::cout;
const int mod = 998244353;
const int mod2 = 974849; 
const int w = sqrt(mod2);
const int limit = 3 * (w + 1) * 1024;
int djq[limit], arr[mod2];
using u64 = unsigned long long;
int inv(int x) {
	const int p = (u64) x * arr[x >> 10] % mod;
	return (u64) arr[x >> 10] * (p < limit ? djq[p] : mod - djq[mod - p]) % mod;
}
void init(int) {
	for(int i = w;i >= 1;--i) {
		std::function<int(int)> getinv = [&](int x) {
			return x == 1 ? 1 : mod2 - u64(mod2 / x) * getinv(mod2 % x) % mod2;
		};
		int inv = getinv(i);
		for(int j = 1;j <= w;++j) {
			arr[(u64) j * inv % mod2] = i;
			arr[mod2 - (u64) j * inv % mod2] = i;
		}
	}
	arr[0] = 1;
	djq[1] = 1;
	for(int i = 2;i < limit;++i) {
		djq[i] = mod - u64(mod / i) * djq[mod % i] % mod;
	}
}

詳細信息


Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 22ms
memory: 19676kb

Test #2:

score: 20
Accepted
time: 656ms
memory: 19324kb

Test #3:

score: 30
Accepted
time: 2507ms
memory: 19672kb

Test #4:

score: 20
Accepted
time: 4642ms
memory: 19444kb

Test #5:

score: 20
Accepted
time: 2885ms
memory: 19404kb