QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#370035#5. 在线 O(1) 逆元OneWan100 ✓2857ms24356kbC++201.0kb2024-03-28 21:16:432024-11-05 21:57:56

Judging History

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

  • [2024-11-05 21:57:56]
  • 管理员手动重测本题所有提交记录
  • 测评结果:100
  • 用时:2857ms
  • 内存:24356kb
  • [2024-03-28 21:16:45]
  • 评测
  • 测评结果:100
  • 用时:2436ms
  • 内存:24296kb
  • [2024-03-28 21:16:43]
  • 提交

answer

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

const int B = 1 << 10, T = 1 << 20;
struct Inverse {
	int mod;
	int f[T + 1], p[T + 1], buf[T * 3 + 3], *I = buf + T;
	Inverse(int mod) : mod(mod) {
		for (int i = 1 ; i <= B ; i++) {
			int s = 0, d = i << 10;
			for (int j = 1 ; j <= T ; j++) {
				if ((s += d) >= mod) s -= mod;
				if (s <= T) {
					if (f[j] == 0) {
						f[j] = i;
						p[j] = s;
					}
				} else if (s >= mod - T) {
					if (f[j] == 0) {
						f[j] = i;
						p[j] = s - mod;
					}
				} else {
					int t = (mod - T - s - 1) / d;
					s += t * d;
					j += 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 operator()(int x) {
		return 1LL * I[p[x >> 10] + (x & 1023) * f[x >> 10]] * f[x >> 10] % mod;
	}
}; // Inverse

void init(int p) {
	
}
Inverse invs(998244353);
int inv(int x) {
	return invs(x);
}

Details


Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 28ms
memory: 24208kb

Test #2:

score: 20
Accepted
time: 306ms
memory: 24216kb

Test #3:

score: 30
Accepted
time: 1400ms
memory: 24356kb

Test #4:

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

Test #5:

score: 20
Accepted
time: 2857ms
memory: 24148kb