QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#919953#5. 在线 O(1) 逆元六点共圆队 (Jia Zhichen, Liu Jiameng, Yin Weizhen)#100 ✓2183ms24336kbC++141.0kb2025-02-28 14:20:512025-02-28 14:20:52

Judging History

This is the latest submission verdict.

  • [2025-02-28 14:20:52]
  • Judged
  • Verdict: 100
  • Time: 2183ms
  • Memory: 24336kb
  • [2025-02-28 14:20:51]
  • Submitted

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


Pretests


Final Tests

Test #1:

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

Test #2:

score: 20
Accepted
time: 232ms
memory: 24336kb

Test #3:

score: 30
Accepted
time: 1105ms
memory: 24288kb

Test #4:

score: 20
Accepted
time: 1743ms
memory: 24272kb

Test #5:

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