QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#545008#8717. 骰子shiqiaqiaya#TL 0ms3696kbC++202.7kb2024-09-02 21:44:062024-09-02 21:44:06

Judging History

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

  • [2024-09-02 21:44:06]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3696kb
  • [2024-09-02 21:44:06]
  • 提交

answer

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>    // 包含 tree、gp_hash_table、cc_hash_table
#include <ext/pb_ds/priority_queue.hpp> // 引入后使用 STL 的堆需要 std::
#include <ext/rope>
using namespace __gnu_pbds;
using namespace __gnu_cxx;
using namespace std;
template<typename key, typename val = null_type, typename cmp = less<>>
using rb_tree = tree<key, val, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<typename key, typename cmp = less<>>
using pairing_heap = __gnu_pbds::priority_queue<key, cmp>;
typedef long long ll;
#define int long long
mt19937_64 rd(time(0));

const int mod = 1e9 + 7;

auto binpow = [](int a, int b, int res = 1) {
    for (a %= mod; b; b >>= 1, (a *= a) %= mod) {
        if (b & 1) (res *= a) %= mod;
    }
    return res;
};

void QAQ() {
    int n, m, q;
    cin >> n >> m >> q;

    vector<int> b(m + 1);

    for (int i = 0; i <= m; i++) {
        cin >> b[i];
    }

    vector p(n + 1, vector<array<int, 2>>(2 * m + 1)), dp(n + 1, vector<array<int, 2>>(2 * m + 1)), zero(n + 1, vector<array<int, 2>>(2 * m + 1));

    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= m; j++) {
            cin >> p[i][j][0];
            if (p[i][j][0] == mod) {
                p[i][j] = {0, 1};
            }
        }
    }

    auto jia = [&](array<int, 2> & a, array<int, 2> & b) -> array<int, 2> {
        int t = min(a[1], b[1]);
        if (a[0] + b[0] == mod) {
            t++;
        }
        return array<int, 2>{(a[0] + b[0]) % mod, t};
    };

    auto mul = [&](array<int, 2> & a, array<int, 2> & b) -> array<int, 2> {
        return array<int, 2>{a[0] * b[0] % mod, a[1] * b[1]};
    };

    auto div = [&](array<int, 2> & a, array<int, 2> & b) {
        return array<int, 2>{a[0] * binpow(b[0], mod - 2) % mod, a[1] - b[1]};
    };

    dp[0][0] = {1, 0};

    for (int i  = 1; i <= n ; i++)
        for (int j = 0 ; j <= 2 * m; j++)
            for (int k = 0; k <= j; k++) {
                    auto tmp = mul(dp[i - 1][j - k], p[i][k]);
                    dp[i][j] = jia(dp[i][j], tmp);
                }

    while (q--) {
        int l, r;
        cin >> l >> r;

        int ans = 0;

        for (int j = 0; j <= 2 * m; j++) {
            for (int i = 0; i <= j; i++) {
                if (j - i > m) {
                    continue;
                }
                auto tmp = div(dp[r][j], dp[l - 1][i]);
                int tt = tmp[1] ? 0 : tmp[0];
                (ans += tt * b[j - i]) %= mod;
            }
        }

        cout << ans << "\n";
    }
}

signed main() {
    cin.tie(0) -> sync_with_stdio(0);
    int t = 1;
    // cin >> t;

    while (t--) {
        QAQ();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3692kb

input:

3 3 3
4 3 2 1
0 1 0 1000000007
0 500000004 0 500000004
0 0 500000004 500000004
1 1
1 2
1 3

output:

3
1
0

result:

ok 3 number(s): "3 1 0"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3668kb

input:

3 3 6
4 3 2 1
1000000007 0 1 0
1000000007 1 0 0
1000000007 0 1 0
1 1
1 2
1 3
2 2
2 3
3 3

output:

2
1
0
3
1
2

result:

ok 6 numbers

Test #3:

score: 0
Accepted
time: 0ms
memory: 3696kb

input:

1 1 1
604063100 57375033
742299910 257700098
1 1

output:

148903503

result:

ok 1 number(s): "148903503"

Test #4:

score: -100
Time Limit Exceeded

input:

1500 200 600000
253665324 876103781 804024983 929290295 908790466 176299158 528078340 696679927 416465140 509641654 705083449 361711737 250659645 735832780 35321360 383752049 203979021 178832532 785212637 514502839 169840231 65809146 504755349 516829442 382478309 901925498 142312128 782336477 741339...

output:


result: