QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#422177 | #8717. 骰子 | ucup-team173 | AC ✓ | 1023ms | 8552kb | C++20 | 2.8kb | 2024-05-26 21:39:10 | 2024-05-26 21:39:11 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
constexpr int P = 1e9 + 7;
int qpow(int a, int b) {
int res = 1;
while(b) {
if(b & 1) {
res = 1LL * res * a % P;
}
a = 1LL * a * a % P;
b >>= 1;
}
return res;
}
int inv(int a) {
return qpow(a, P - 2);
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
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, vector<int>(m + 1)), ip(n, vector<int>(m + 1));
vector<int> del(n, -1);
for(int i = 0; i < n; i++) {
for(int j = 0; j <= m; j++) {
cin >> p[i][j];
p[i][j] >= P ? p[i][j] -= P : 0;
if(p[i][j] && del[i] == -1) {
del[i] = j;
}
}
for(int j = del[i]; j <= m; j++) {
p[i][j - del[i]] = p[i][j];
}
for(int j = m - del[i] + 1; j <= m; j++) {
p[i][j] = 0;
}
ip[i][0] = inv(p[i][0]);
for(int j = 1; j <= m; j++) {
int now = 0;
for(int k = 0; k < j; k++) {
now = (now + 1LL * ip[i][k] * p[i][j - k]) % P;
}
ip[i][j] = 1ll * (P - now) * ip[i][0] % P;
}
if(i) {
del[i] += del[i - 1];
}
}
auto mul = [&](vector<int> &f, vector<int> &g) {
vector<int> res(m + 1);
for(int i = 0; i <= m; i++) {
for(int j = 0; j <= i; j++) {
res[i] = (res[i] + 1LL * f[j] * g[i - j]) % P;
}
}
return res;
};
vector pre(n, vector<int>(m + 1)), ipre(n, vector<int>(m + 1));
pre[0] = p[0], ipre[0] = ip[0];
for(int i = 1; i < n; i++) {
pre[i] = mul(pre[i - 1], p[i]);
ipre[i] = mul(ip[i], ipre[i - 1]);
}
reverse(b.begin(), b.end());
for(int i = 0; i < n; i++) {
pre[i] = mul(pre[i], b);
}
while(q--) {
int l, r;
cin >> l >> r;
l--, r--;
int delx = del[r] - (l ? del[l - 1] : 0);
if(m - delx < 0) {
cout << 0 << '\n';
continue;
}
if(l == 0) {
cout << pre[r][m - delx] << '\n';
continue;
}
int res = 0;
for(int i = 0; i <= m - delx; i++) {
res = (res + 1LL * pre[r][i] * ipre[l - 1][m - delx - i]) % P;
}
cout << res << '\n';
}
return 0;
}
/*
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
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
*/
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3808kb
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: 3844kb
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: 3604kb
input:
1 1 1 604063100 57375033 742299910 257700098 1 1
output:
148903503
result:
ok 1 number(s): "148903503"
Test #4:
score: 0
Accepted
time: 1023ms
memory: 8552kb
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:
66394849 858043015 290088512 433850735 16359498 544692508 495705795 390858705 334940115 441003348 589429674 891250455 147055038 949270774 782296292 854444995 608076278 772991067 609961969 3444634 534397763 659524291 384815421 329963211 259265811 214554716 662015873 465616975 355211926 398786302 7484...
result:
ok 600000 numbers
Test #5:
score: 0
Accepted
time: 4ms
memory: 3528kb
input:
10 200 50 370772932 487085918 522119313 202271129 795784341 241675432 84696649 6593125 142447175 433043082 912818145 541105733 352679271 713064369 909540704 642928848 262928894 910729006 19720645 257900859 152127142 466747981 548396756 424075620 112979677 6097940 549613699 409134160 673872615 423969...
output:
95478933 40420846 949457584 785743027 889119897 679023045 369149401 975015432 354462393 485444538 29208842 586846064 186163820 22554968 824615211 569553393 744645623 242702753 632410029 205596998 61853702 489103277 732828674 100756683 141691367 282384748 410111173 962211860 167960231 479439671 24188...
result:
ok 50 numbers
Test #6:
score: 0
Accepted
time: 773ms
memory: 8528kb
input:
1451 196 495733 867638655 902055413 105294111 137664336 471592456 918420578 125072731 308929978 27685746 452519696 98422383 706168360 78074387 292091353 618373494 369467100 162485874 836155739 298771673 885513404 838310084 906054277 607746923 87340077 246700830 757296916 704582501 989205453 31137463...
output:
460690386 278678842 53059823 742261043 218023681 845226442 807934157 947218276 439209786 134749344 333062838 85472333 716670499 918798477 869889873 62065687 294021428 402449069 219660955 196254975 555611425 92638506 562044910 38568438 356602242 709735280 604757128 569518126 36515714 351120221 532138...
result:
ok 495733 numbers
Test #7:
score: 0
Accepted
time: 598ms
memory: 8496kb
input:
1500 200 540000 223660186 89468677 759079474 404830014 979472869 83267050 83563367 677675529 859956529 155987948 353693543 77500819 86016820 650321973 494266976 680564693 452260610 995412525 340962913 500500716 566751189 684928139 427671993 89692208 6597269 333294046 339922474 694930232 485180083 51...
output:
0 0 336294876 467089346 0 982024564 0 818667512 696589964 622577755 0 0 0 785586193 0 0 944327932 0 509627964 843415527 969890452 0 937503991 770845465 962611688 193026222 724721775 811172009 778901622 609135235 0 358665248 124966698 551642216 918648252 0 641301974 839720389 93459623 241080994 21718...
result:
ok 540000 numbers
Test #8:
score: 0
Accepted
time: 585ms
memory: 8072kb
input:
1494 170 600000 401180116 688567218 62843723 545029957 206920560 177345580 769762918 829272212 462277941 753515932 302840629 970657356 916220281 213592777 862002384 190527510 91750240 877239697 471954197 940033161 742402869 632372244 244285549 458360335 642939560 70979153 205902868 36837822 26680432...
output:
464045721 885048076 0 492090219 468239489 828817640 242844948 875727270 0 100655424 980764960 985325822 80971612 843425086 674298027 575445303 501679520 629174460 132121609 311125954 897030977 676292437 206048315 0 327770406 934980265 136154222 0 253128449 293936905 0 374315641 7827333 342855032 631...
result:
ok 600000 numbers
Extra Test:
score: 0
Extra Test Passed