QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#667810#5. 在线 O(1) 逆元Fiatiustitia70 992ms3744kbC++202.5kb2024-10-23 08:19:042024-10-23 08:19:10

Judging History

你现在查看的是测评时间为 2024-10-23 08:19:10 的历史记录

  • [2024-11-05 22:06:47]
  • 管理员手动重测本题所有提交记录
  • 测评结果:60
  • 用时:4958ms
  • 内存:3888kb
  • [2024-10-23 08:19:10]
  • 评测
  • 测评结果:70
  • 用时:992ms
  • 内存:3744kb
  • [2024-10-23 08:19:04]
  • 提交

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;
// }

详细


Pretests


Final Tests

Test #1:

score: 30
Accepted
time: 10ms
memory: 3740kb

Test #2:

score: 40
Accepted
time: 992ms
memory: 3744kb

Test #3:

score: 0
Time Limit Exceeded