QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#338421 | #5. 在线 O(1) 逆元 | 275307894a | 100 ✓ | 3810ms | 25140kb | C++14 | 1.4kb | 2024-02-25 21:39:39 | 2024-11-05 21:57:41 |
Judging History
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;
}
詳細信息
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 19ms
memory: 25116kb
Test #2:
score: 20
Accepted
time: 496ms
memory: 25140kb
Test #3:
score: 30
Accepted
time: 2290ms
memory: 25080kb
Test #4:
score: 20
Accepted
time: 3305ms
memory: 25128kb
Test #5:
score: 20
Accepted
time: 3810ms
memory: 25080kb