QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#460324#5. 在线 O(1) 逆元Ciriya666100 ✓1851ms24376kbC++171.0kb2024-07-01 13:52:402024-07-01 13:52:41

Judging History

你现在查看的是测评时间为 2024-07-01 13:52:41 的历史记录

  • [2024-11-05 21:59:40]
  • 管理员手动重测本题所有提交记录
  • 测评结果:100
  • 用时:1711ms
  • 内存:24332kb
  • [2024-07-01 13:52:41]
  • 评测
  • 测评结果:100
  • 用时:1851ms
  • 内存:24376kb
  • [2024-07-01 13:52:40]
  • 提交

answer

#include "inv.h"
#include <bits/stdc++.h>

using i64 = long long;

constexpr int P = 998244353;

namespace Inversion {

	static constexpr int B = (1 << 10), T = (1 << 20);

	int f[T + 5], p[T + 5], buf[T * 3 + 5];
	int *I = buf + T;

	void init() {
		for (int u = 1; u <= B; u++) {
			int s = 0, d = (u << 10);
			for (int a = 1; a <= T; a++) {
				if ((s += d) >= P) s -= P;
				if (s <= T) {
					if (!f[a]) f[a] = u, p[a] = s;
                    continue;
				} 
                if (s >= P - T) {
                    if (!f[a]) f[a] = u, p[a] = s - P;
                    continue;
				} 
                int t = (P - T - s - 1) / d;
                s += t * d, a += t;
			}
		}

		I[1] = f[0] = 1;
		for (int i = 2; i <= (T << 1); i++) I[i] = 1ll * (P - P / i) * I[P % i] % P;
		for (int i = -1; i >= -T; i--) I[i] = P - I[-i];
	}

	int inv(int x) { return 1ll * I[p[x >> 10] + (x & 1023) * f[x >> 10]] * f[x >> 10] % P; }
};

void init(int p) {
	Inversion::init();
}

int inv(int x) {
	return Inversion::inv(x);
}

Details

Test #1:

score: 30
Accepted
time: 24ms
memory: 24268kb

Test #2:

score: 40
Accepted
time: 194ms
memory: 24376kb

Test #3:

score: 30
Accepted
time: 1851ms
memory: 24236kb