QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#479132#5. 在线 O(1) 逆元A_programmer#100 ✓3495ms25280kbC++171.0kb2024-07-15 15:17:132024-07-15 15:17:14

Judging History

你现在查看的是测评时间为 2024-07-15 15:17:14 的历史记录

  • [2024-11-05 22:00:17]
  • 管理员手动重测本题所有提交记录
  • 测评结果:100
  • 用时:5213ms
  • 内存:26204kb
  • [2024-07-15 15:17:14]
  • 评测
  • 测评结果:100
  • 用时:3495ms
  • 内存:25280kb
  • [2024-07-15 15:17:13]
  • 提交

answer

#include "inv.h"
#include <bits/stdc++.h>
using namespace std;

const int B = 1 << 10, B2 = 1 << 20;

int Inv[B2 << 2], mod;
int U[B2 | 10], vl[B2 | 10];
int* iv;

void init(int P)
{
    iv = Inv + B2;
    iv[1] = 1; mod = P;
    for (int i = 2; i <= (B2 << 1); i++) iv[i] = 1ll * (P - P / i) * iv[P % i] % P;
    for (int i = 1; i <= B2; i++) iv[-i] = mod - iv[i];

    U[0] = 1;
    for (int u = 1; u <= B; u++)
    {
        int uB = u << 10, sum = 0;
        for (int k = 1; k <= B2; k++)
        {
            sum = ((sum += uB) >= P ? sum - P : sum);
            if (sum <= B2)
            {
                if (!U[k]) U[k] = u, vl[k] = sum;
            }
            else if (sum >= P - B2)
            {
                if (!U[k]) U[k] = u, vl[k] = sum - P;
            }
            else
            {
                int nxt = (P - B2 - sum - 1) / uB;
                k += nxt, sum += nxt * uB;
            }
        }
    }
}
int inv(int x) { return 1ll * iv[vl[x >> 10] + (x & 1023) * U[x >> 10]] * U[x >> 10] % mod; }

Details

Test #1:

score: 30
Accepted
time: 23ms
memory: 24988kb

Test #2:

score: 40
Accepted
time: 276ms
memory: 24720kb

Test #3:

score: 30
Accepted
time: 3495ms
memory: 25280kb