QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#24686#5. 在线 O(1) 逆元skip2004100 ✓4793ms35352kbC++201.4kb2022-04-02 11:02:032024-11-05 21:47:01

Judging History

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

  • [2024-11-05 21:47:01]
  • 管理员手动重测本题所有提交记录
  • 测评结果:100
  • 用时:4793ms
  • 内存:35352kb
  • [2024-11-05 21:43:29]
  • 管理员手动重测本题所有提交记录
  • 测评结果:100
  • 用时:2867ms
  • 内存:35384kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-04-30 06:29:11]
  • 评测
  • 测评结果:100
  • 用时:5979ms
  • 内存:35080kb
  • [2022-04-02 11:02:03]
  • 提交

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 mem[limit * 2 + 10], *const djq = mem + limit + 5;
using u64 = unsigned long long;
using u32 = unsigned;
struct Div {
	u32 a, b;
	inline void operator = (int w) {
		a = w, b = ((u64) w << 32) / mod;
	}
	inline friend int operator * (const int & x, const Div & y) {
		return (u64) x * y.a - (((u64)x * y.b + (1ull << 31)) >> 32) * mod;
	}
} arr[mod2];
int inv(int x) {
	int ans = djq[x * arr[x >> 10]] * arr[x >> 10];
	return ans + (ans >> 31 & 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 = 0;j <= w;++j) {
			arr[(u64) j * inv % mod2] = i;
			arr[mod2 - (u64) j * inv % mod2] = mod - i;
		}
	}
	djq[1] = 1;
	for(int i = 2;i < limit;++i) djq[i] = mod - u64(mod / i) * djq[mod % i] % mod;
	for(int i = 1;i < limit;++i) djq[-i] = mod - djq[i];
}
/*
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0);
	init(mod);
	for(int i = 1;i < mod;++i) {
		if(u64(inv(i)) * i % mod != 1) {
			cout << inv(i) << ' ' << i << '\n';
			return 0;
		}
		if(i % 1000000 == 0) {
			std::cerr << "debug : " << i << std::endl;
		}

	}
}
*/

Details


Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 25ms
memory: 35112kb

Test #2:

score: 20
Accepted
time: 724ms
memory: 35044kb

Test #3:

score: 30
Accepted
time: 1662ms
memory: 35000kb

Test #4:

score: 20
Accepted
time: 3235ms
memory: 35352kb

Test #5:

score: 20
Accepted
time: 4793ms
memory: 35336kb