QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#420251 | #8717. 骰子 | alpha1022 | RE | 1ms | 4088kb | C++14 | 2.3kb | 2024-05-24 15:50:50 | 2024-05-24 15:50:51 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
int norm(int x) { return x >= mod ? x - mod : x; }
int reduce(int x) { return x < 0 ? x + mod : x; }
int neg(int x) { return x ? mod - x : 0; }
int quo2(int x) { return (x + (x & 1 ? mod : 0)) >> 1; }
void add(int &x, int y) { x += y, x = x >= mod ? x - mod : x; }
void sub(int &x, int y) { x -= y, x = x < 0 ? x + mod : x; }
void fam(int &x, int y, int z) { x = (x + (ll)y * z) % mod; }
int mpow(int a, int b) {
int ret = 1;
for (; b; b >>= 1) {
if (b & 1) ret = (ll)ret * a % mod;
a = (ll)a * a % mod;
}
return ret;
}
int main() {
int n, m, q; scanf("%d%d%d", &n, &m, &q);
vector<int> b(m + 1);
for (int i = m; i >= 0; --i) scanf("%d", b.data() + i);
vector<vector<int>> a(n, vector<int>(m + 1));
for (int i = 0; i < n; ++i)
for (int j = 0; j <= m; ++j) scanf("%d", a[i].data() + j);
vector<int> ans(q);
vector<tuple<int, int, int>> qry;
for (int i = 0; i < q; ++i) {
int l, r; scanf("%d%d", &l, &r), --l, qry.emplace_back(l, r, i);
}
auto divideConquer = [&](auto &self, int l, int r, vector<tuple<int, int, int>> qry) {
if (qry.empty()) return ;
if (l + 1 == r) {
int s = 0;
for (int i = 0; i <= m; ++i) fam(s, a[l][i], b[m - i]);
for (auto [ql, qr, i] : qry) ans[i] = s;
return ;
}
int mid = (l + r + 1) >> 1;
vector<vector<int>> f(r - l + 1, vector<int>(m + 1));
f[mid][0] = 1;
for (int i = mid; i < r; ++i)
for (int j = 0; j <= m; ++j)
for (int k = 0; j + k <= m; ++k)
fam(f[i - l + 1][j + k], f[i - l][j], a[i][k]);
f[mid] = b;
for (int i = mid - 1; i >= l; --i)
for (int j = 0; j <= m; ++j)
for (int k = 0; j + k <= m; ++k)
fam(f[i - l][j + k], f[i - l + 1][j], a[i][k]);
vector<tuple<int, int, int>> L, R;
for (auto [ql, qr, i] : qry)
if (qr <= mid) L.emplace_back(ql, qr, i);
else if (ql >= mid) R.emplace_back(ql, qr, i);
else for (int j = 0; j <= m; ++j) fam(ans[i], f[ql - l][j], f[qr - l][m - j]);
self(self, l, mid, L), self(self, mid, r, R);
};
divideConquer(divideConquer, 0, n, qry);
for (int i = 0; i < q; ++i) printf("%d\n", ans[i]);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4088kb
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: 3832kb
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: 3776kb
input:
1 1 1 604063100 57375033 742299910 257700098 1 1
output:
148903503
result:
ok 1 number(s): "148903503"
Test #4:
score: -100
Runtime Error
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...