QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#499423#5. 在线 O(1) 逆元lonelywolf100 ✓3793ms24292kbC++231.1kb2024-07-31 14:04:382024-11-05 22:02:41

Judging History

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

  • [2024-11-05 22:02:41]
  • 管理员手动重测本题所有提交记录
  • 测评结果:100
  • 用时:3793ms
  • 内存:24292kb
  • [2024-07-31 14:04:39]
  • 评测
  • 测评结果:100
  • 用时:2171ms
  • 内存:24368kb
  • [2024-07-31 14:04:38]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

using i64 = long long;

constexpr int mod = 998244353;

struct 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) >= mod) s -= mod;
				if (s <= T) {
					if (!f[a]) f[a] = u, p[a] = s;
                    continue;
				} 
                if (s >= mod - T) {
                    if (!f[a]) f[a] = u, p[a] = s - mod;
                    continue;
				} 
                int t = (mod - 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 * (mod - mod / i) * I[mod % i] % mod;
		for (int i = -1; i >= -T; i--) I[i] = mod - I[-i];
	}

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

Inversion inver;

void init(int p) {
	inver.init();
}

int inv(int x) {
	return inver.inv(x);
}

Details


Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 27ms
memory: 24228kb

Test #2:

score: 20
Accepted
time: 358ms
memory: 24172kb

Test #3:

score: 30
Accepted
time: 1509ms
memory: 24172kb

Test #4:

score: 20
Accepted
time: 2916ms
memory: 24152kb

Test #5:

score: 20
Accepted
time: 3793ms
memory: 24292kb