QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#479764#5. 在线 O(1) 逆元BlackPanda100 ✓1723ms24308kbC++141.0kb2024-07-15 20:46:532024-11-05 22:00:30

Judging History

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

  • [2024-11-05 22:00:30]
  • 管理员手动重测本题所有提交记录
  • 测评结果:100
  • 用时:1723ms
  • 内存:24308kb
  • [2024-07-15 20:46:53]
  • 评测
  • 测评结果:100
  • 用时:1686ms
  • 内存:24364kb
  • [2024-07-15 20:46:53]
  • 提交

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);
}

詳細信息


Pretests


Final Tests

Test #1:

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

Test #2:

score: 20
Accepted
time: 195ms
memory: 24212kb

Test #3:

score: 30
Accepted
time: 875ms
memory: 24308kb

Test #4:

score: 20
Accepted
time: 1374ms
memory: 24176kb

Test #5:

score: 20
Accepted
time: 1723ms
memory: 24308kb