QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#667810 | #5. 在线 O(1) 逆元 | Fiatiustitia | 60 | 4958ms | 3888kb | C++20 | 2.5kb | 2024-10-23 08:19:04 | 2024-11-05 22:06:47 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int P = 998244353;
template <const int T>
struct ModInt
{
const static int mod = T;
int x;
ModInt(int x = 0) : x(x % mod) {}
ModInt(long long x) : x(int(x % mod)) {}
int val() { return x; }
ModInt operator+(const ModInt &a) const
{
int x0 = x + a.x;
return ModInt(x0 < mod ? x0 : x0 - mod);
}
ModInt operator-(const ModInt &a) const
{
int x0 = x - a.x;
return ModInt(x0 < 0 ? x0 + mod : x0);
}
ModInt operator*(const ModInt &a) const { return ModInt(1LL * x * a.x % mod); }
ModInt operator/(const ModInt &a) const { return *this * a.inv(); }
void operator+=(const ModInt &a)
{
x += a.x;
if (x >= mod)
x -= mod;
}
void operator-=(const ModInt &a)
{
x -= a.x;
if (x < 0)
x += mod;
}
void operator*=(const ModInt &a) { x = 1LL * x * a.x % mod; }
void operator/=(const ModInt &a) { *this = *this / a; }
friend ModInt operator+(int y, const ModInt &a)
{
int x0 = y + a.x;
return ModInt(x0 < mod ? x0 : x0 - mod);
}
friend ModInt operator-(int y, const ModInt &a)
{
int x0 = y - a.x;
return ModInt(x0 < 0 ? x0 + mod : x0);
}
friend ModInt operator*(int y, const ModInt &a) { return ModInt(1LL * y * a.x % mod); }
friend ModInt operator/(int y, const ModInt &a) { return ModInt(y) / a; }
friend ostream &operator<<(ostream &os, const ModInt &a) { return os << a.x; }
friend istream &operator>>(istream &is, ModInt &t) { return is >> t.x; }
ModInt pow(int64_t n) const
{
ModInt res(1), mul(x);
while (n)
{
if (n & 1)
res *= mul;
mul *= mul;
n >>= 1;
}
return res;
}
ModInt inv() const
{
int a = x, b = mod, u = 1, v = 0;
while (b)
{
int t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
if (u < 0)
u += mod;
return u;
}
};
typedef ModInt<P> mint;
void init(int p)
{
}
int inv(int x)
{
return mint(x).inv().x;
}
// void solve()
// {
// }
// int main()
// {
// #ifdef LOCAL
// freopen("data.in", "r", stdin);
// freopen("data.out", "w", stdout);
// #endif
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// solve();
// return 0;
// }
Details
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 10ms
memory: 3764kb
Test #2:
score: 20
Accepted
time: 992ms
memory: 3888kb
Test #3:
score: 30
Accepted
time: 4958ms
memory: 3840kb
Test #4:
score: 0
Time Limit Exceeded
Test #5:
score: 0
Time Limit Exceeded