QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#338657#5. 在线 O(1) 逆元275307894a100 ✓2328ms18012kbC++141.4kb2024-02-26 07:08:072024-11-05 21:57:44

Judging History

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

  • [2024-11-05 21:57:44]
  • 管理员手动重测本题所有提交记录
  • 测评结果:100
  • 用时:2328ms
  • 内存:18012kb
  • [2024-02-26 07:08:08]
  • 评测
  • 测评结果:100
  • 用时:2875ms
  • 内存:18152kb
  • [2024-02-26 07:08:07]
  • 提交

answer

#include<bits/stdc++.h>
#include "inv.h"
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=(1<<21)+5,M=N*10+5,K=1000+5,mod=998244353,Mod=+-1;const db eps=1e-9;const ll INF=1e18+7;mt19937 rnd(263082);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
	Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
	Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
	#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
}using namespace Debug;
const int B=1024;
int pl[N],iv[N];
void init(int p){
	const int n=2*B*B;
	iv[1]=1;
	for(int i=2;i<=n;i++) iv[i]=1ll*(mod-iv[mod%i])*(mod/i)%mod;
	for(int i=1;i<=B;i++){
		int x=0;
		while(x<=B*B){
			ll w=1ll*x*B*i%mod;
			if(w<=B*B||w>=mod-B*B) pl[x]=i,x++;
			else{
				x+=(mod-B*B-w+B*i-1)/(B*i);
			}
		}
	}
	// gdb(pl[100000]*100000ll*B%mod);
}
int inv(int x){
	ll w=1ll*x*pl[x>>10]%mod;
	if(w<=2*B*B) return 1ll*iv[w]*pl[x/B]%mod;
	else return 1ll*(mod-iv[mod-w])*pl[x/B]%mod;
}

Details


Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 17ms
memory: 16932kb

Test #2:

score: 20
Accepted
time: 251ms
memory: 17476kb

Test #3:

score: 30
Accepted
time: 1190ms
memory: 17516kb

Test #4:

score: 20
Accepted
time: 1884ms
memory: 17636kb

Test #5:

score: 20
Accepted
time: 2328ms
memory: 18012kb