QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#92082#5. 在线 O(1) 逆元Crysfly#100 ✓1929ms19712kbC++111.3kb2023-03-30 10:27:102024-11-05 21:47:52

Judging History

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

  • [2024-11-05 21:47:52]
  • 管理员手动重测本题所有提交记录
  • 测评结果:100
  • 用时:1929ms
  • 内存:19712kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-30 10:27:11]
  • 评测
  • 测评结果:100
  • 用时:5896ms
  • 内存:19320kb
  • [2023-03-30 10:27:10]
  • 提交

answer

/*
不会卡常 /kel
存个 skip2004 的代码在这。。 
*/ 

#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;
	/*
	   if(p >= limit && p <= mod - limit) {
	   std::cerr << "debug : " << x << '\n';
	   }
	   */
	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] = mod - i;
		}
	}
	arr[0] = 1;
	// 0 <= x * arr[x] - k * mod2 < w, and arr[x] < w, k < w
	// 998244353 = mod2 * 1024 - 1023
	// 0 <= 1024x * arr[x] - k * 998244353 < w * 1024 + 1023 * k
	// 0 <= (1024x + y) * arr[x] - k * 998244353 < w * 1024 + 1023 * k + 1024 * w
	djq[1] = 1;
	// 等下再优化这个
	for(int i = 2;i < limit;++i) {
		djq[i] = mod - u64(mod / i) * djq[mod % i] % mod;
	}
}

Details


Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 14ms
memory: 19456kb

Test #2:

score: 20
Accepted
time: 204ms
memory: 19460kb

Test #3:

score: 30
Accepted
time: 971ms
memory: 19384kb

Test #4:

score: 20
Accepted
time: 1554ms
memory: 19424kb

Test #5:

score: 20
Accepted
time: 1929ms
memory: 19712kb