QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#795761#5. 在线 O(1) 逆元wujiarui100 ✓2184ms30508kbC++141.2kb2024-12-01 00:15:402024-12-01 00:15:40

Judging History

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

  • [2024-12-01 00:15:40]
  • 评测
  • 测评结果:100
  • 用时:2184ms
  • 内存:30508kb
  • [2024-12-01 00:15:40]
  • 提交

answer

#include<bits/stdc++.h>
#include "inv.h"
#define L(i, j, k) for(int i = (j); i <= (k); ++i)
#define R(i, j, k) for(int i = (j); i >= (k); --i)
#define ll long long 
#define vi vector < int > 
#define sz(a) ((int) (a).size())
#define ll long long 
#define ull unsigned long long
#define me(a, x) memset(a, x, sizeof(a)) 
#define eb emplace_back
using namespace std;
const int B = 1024, mod = 998244353, N = (1 << 21) + 1;
int K, pool[N * 2], *iv = pool + N;
struct M {
	int ml, dis; 
} mp[N];
int inv(int w) {
	M d = mp[w >> 10];
	return (ull) iv[w * d.ml - d.dis] * (mod + d.ml) % mod;
} 
void init(int rp) {
	K = mod / B;
	int Rlim = mod - K;
	L(fb, 1, B) {
		int cur = 0, Add = fb * B;
		for(int p = 0; p <= K; ) {
			if(cur <= K) mp[p].ml = fb;
			else if(cur > Rlim) mp[p].ml = -fb;
			else {
				int A = (Rlim - cur) / Add;
				cur += A * Add, p += A;
			}
			cur += Add, ++p;
			if(cur >= mod) cur -= mod; 
		}
	}
	int count = 0;
	L(i, 1, K) 
		if(mp[i].ml > 0) mp[i].dis = (ll) mp[i].ml * i * B / mod * mod, ++count;
		else mp[i].dis = (ll) mp[i].ml * i * B / mod * mod - mod, ++count;
	iv[1] = 1;
	L(i, 2, N - 1) iv[i] = (ll) iv[mod % i] * (mod - mod / i) % mod;
	L(i, 1, N - 1) iv[-i] = mod - iv[i];
}

详细


Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 22ms
memory: 30508kb

Test #2:

score: 20
Accepted
time: 229ms
memory: 30432kb

Test #3:

score: 30
Accepted
time: 1086ms
memory: 30436kb

Test #4:

score: 20
Accepted
time: 1670ms
memory: 30320kb

Test #5:

score: 20
Accepted
time: 2184ms
memory: 30480kb