QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#338421#5. 在线 O(1) 逆元275307894a100 ✓2966ms25188kbC++141.4kb2024-02-25 21:39:392024-02-25 21:39:39

Judging History

你现在查看的是测评时间为 2024-02-25 21:39:39 的历史记录

  • [2024-11-05 21:57:41]
  • 管理员手动重测本题所有提交记录
  • 测评结果:100
  • 用时:3810ms
  • 内存:25140kb
  • [2024-02-25 21:39:39]
  • 评测
  • 测评结果:100
  • 用时:2966ms
  • 内存:25188kb
  • [2024-02-25 21:39:39]
  • 提交

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=2e6+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;
ll iv[N];const int B=1e3;
int pl[N];
void init(int p){
	const int n=2e6;
	iv[1]=1;
	for(int i=2;i<=n;i++) iv[i]=(mod-iv[mod%i])*(mod/i)%mod;
	for(int i=1;i<=1000;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/B]%mod;
	if(w<=2*B*B) return iv[w]*pl[x/B]%mod;
	else return (mod-iv[mod-w])*pl[x/B]%mod;
}

詳細信息

Test #1:

score: 30
Accepted
time: 25ms
memory: 25144kb

Test #2:

score: 40
Accepted
time: 320ms
memory: 25188kb

Test #3:

score: 30
Accepted
time: 2966ms
memory: 25060kb