QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#106148#5. 在线 O(1) 逆元zhoukangyang100 ✓3040ms38468kbC++171.2kb2023-05-16 18:33:562024-11-05 21:49:48

Judging History

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

  • [2024-11-05 21:49:48]
  • 管理员手动重测本题所有提交记录
  • 测评结果:100
  • 用时:3040ms
  • 内存:38468kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-16 18:34:00]
  • 评测
  • 测评结果:100
  • 用时:5776ms
  • 内存:35088kb
  • [2023-05-16 18:33:56]
  • 提交

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, buf = 3, mod = 998244353, N = 6.1e6 + 7;
int K, iv[N];
struct M {
	int ml, dis; 
} mp[N];
int Inv(int x) {
	return x < N ? iv[x] : (ll) Inv(mod % x) * (mod - mod / x) % mod;
}
int inv(int w) {
	M d = mp[w >> 10];
	return !d.ml ? Inv(w) : (ll) iv[w * d.ml - d.dis] * d.ml % mod;
} 
void init(int rp) {
	K = mod / B;
	L(fb, 1, B * buf) {
		int cur = 0, Add = fb * B;
		for(int p = 0; p <= K; ) {
			if(cur <= K * buf) {
				mp[p].ml = fb;
				cur += Add, ++p;
			} else {
				int A = (mod - cur + Add - 1) / Add;
				cur += A * Add, p += A;
			}
			if(cur >= mod) cur -= mod; 
		}
	}
	int count = 0;
	L(i, 1, K) if(mp[i].ml) mp[i].dis = (ll) mp[i].ml * i * B / mod * mod, ++count;
//	cout << 1. * count / K << endl;
	iv[1] = 1;
	L(i, 2, N - 1) iv[i] = (ll) iv[mod % i] * (mod - mod / i) % mod;
}

Details


Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 62ms
memory: 38404kb

Test #2:

score: 20
Accepted
time: 343ms
memory: 36264kb

Test #3:

score: 30
Accepted
time: 1501ms
memory: 38468kb

Test #4:

score: 20
Accepted
time: 2716ms
memory: 38404kb

Test #5:

score: 20
Accepted
time: 3040ms
memory: 36272kb