QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#381442#8565. Basic Bloomsucup-team004#WA 399ms39280kbC++202.0kb2024-04-07 17:48:232024-04-07 17:48:23

Judging History

你现在查看的是最新测评结果

  • [2024-04-07 17:48:23]
  • 评测
  • 测评结果:WA
  • 用时:399ms
  • 内存:39280kb
  • [2024-04-07 17:48:23]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;

constexpr int N = 1E6;
constexpr int P = 998244353;


long double logdec(long double x){
    return x+std::log(1-std::exp(-x));
}

struct Num {
    int b;
    int l;
    int d;
    long double val;

    Num(int b_, int l_, int d_) : b{b_}, l{l_}, d{d_}, val{logdec(l*std::log(1.0L * b)) - std::log(1.0L *(b-1)) + std::log(1.0L * d)} {}
};

bool operator<(const Num &a, const Num &b) {
    return a.val > b.val;
}

constexpr long double eps = 0;

int power(int a, int b) {
    int res = 1;
    for (; b; b /= 2, a = 1LL * a * a % P) {
        if (b % 2) {
            res = 1LL * res * a % P;
        }
    }
    return res;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    std::vector<Num> num;

    int l[17] {};
    int d[17] {};

    std::priority_queue<Num> pq;

    for (int b = 2; b <= 16; b++) {
        l[b] = 1;
        d[b] = 1;
        pq.emplace(b, l[b], d[b]);
    }
    
    while (num.size() < N) {
        auto x = pq.top();
        pq.pop();
        int b = x.b;
        if (num.empty() || x.val > num.back().val + (eps)) {
            num.push_back(x);
            // if (num.size() % 10000 == 0) {
            //     std::cerr << num.size() << "\n";
            // }
        }
        d[b]++;
        if (d[b] == b) {
            l[b]++;
            d[b] = 1;
        }
        pq.emplace(b, l[b], d[b]);
    }

    std::vector<int> sum(N + 1);
    int inv[17];
    for (int i = 1; i <= 16; i++) {
        inv[i] = power(i, P - 2);
    }
    for (int i = 0; i < N; i++) {
        auto [b, l, d, _] = num[i];
        int res = 1LL * d * (power(b, l) - 1) % P * inv[b - 1] % P;
        sum[i + 1] = (sum[i] + res) % P;
    }

    int t;
    std::cin >> t;

    while (t--) {
        int l, r;
        std::cin >> l >> r;
        l--;
        int ans = (sum[r] - sum[l] + P) % P;
        std::cout << ans << "\n";
    }

    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 399ms
memory: 39280kb

input:

3
1 2
1 10
15 2000

output:

2
15
228757700

result:

wrong answer 1st numbers differ - expected: '3', found: '2'