ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#213597 | #2770. 子序列 | KXG | 20 | 2845ms | 39192kb | C++11 | 2.1kb | 2024-11-12 21:32:30 | 2024-11-12 23:53:21 |
answer
#include <cstdio>
#include <vector>
using namespace std;
const int mod = 1e9 + 7;
int n, m, q, l[200010], r[200010], a[200010];
long long dp[200010][20], ans[200010];
vector<int> queries;
void solve(int L, int R, vector<int> queries) {
if (L == R) {
for (int i = 0; i < queries.size(); i++) {
ans[queries[i]] = 1 + (a[L] % m == 0);
}
return;
}
vector<int> left, right, now;
int mid = (L + R) >> 1;
for (int i = 0; i < queries.size(); i++) {
if (r[queries[i]] <= mid) {
left.push_back(queries[i]);
} else if (l[queries[i]] > mid) {
right.push_back(queries[i]);
} else {
now.push_back(queries[i]);
}
}
solve(L, mid, left);
solve(mid + 1, R, right);
for (int i = 0; i < m; i++) {
dp[mid][i] = dp[mid + 1][i] = 0;
}
dp[mid][0]++;
dp[mid][a[mid] % m]++;
dp[mid + 1][0]++;
dp[mid + 1][a[mid + 1] % m]++;
for (int i = mid - 1; i >= L; i--) {
for (int j = 0; j < m; j++) {
dp[i][j] = dp[i + 1][j];
}
for (int j = 0; j < m; j++) {
dp[i][(j + a[i]) % m] = (dp[i][(j + a[i]) % m] + dp[i + 1][j]) % mod;
}
}
for (int i = mid + 2; i <= R; i++) {
for (int j = 0; j < m; j++) {
dp[i][j] = dp[i - 1][j];
}
for (int j = 0; j < m; j++) {
dp[i][(j + a[i]) % m] = (dp[i][(j + a[i]) % m] + dp[i - 1][j]) % mod;
}
}
for (int i = 0; i < now.size(); i++) {
for (int j = 0; j < m; j++) {
ans[now[i]] = (ans[now[i]] + dp[l[now[i]]][j] * dp[r[now[i]]][(m - j) % m] % mod) % mod;
}
}
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
scanf("%d", &q);
for (int i = 1; i <= q; i++) {
scanf("%d%d", &l[i], &r[i]);
queries.push_back(i);
}
solve(1, n, queries);
for (int i = 1; i <= q; i++) {
printf("%d\n", ans[i]);
}
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 4
Accepted
time: 0ms
memory: 1116kb
input:
10 20 7 5 5 1 7 13 19 10 2 7 10 10 10 6 7 6 8 4 10 8 9 5 8 6 10 5 5 2 6 6 8
output:
1 1 1 9 1 2 2 1 2 1
result:
ok 10 lines
Test #2:
score: 4
Accepted
time: 0ms
memory: 1124kb
input:
10 20 15 0 15 10 6 18 1 13 3 1 10 1 2 4 9 3 7 4 8 6 10 2 3 1 4 2 5 2 9 5 9
output:
2 4 2 2 2 2 4 2 12 3
result:
ok 10 lines
Test #3:
score: 4
Accepted
time: 0ms
memory: 1120kb
input:
10 20 8 9 17 13 10 13 16 11 19 3 10 6 9 3 9 2 6 1 10 5 10 6 10 4 5 2 4 10 10 3 5
output:
2 9 3 56 4 2 1 1 1 2
result:
ok 10 lines
Test #4:
score: 4
Accepted
time: 0ms
memory: 1120kb
input:
10 20 12 8 11 1 0 3 2 3 19 17 10 5 7 1 3 1 10 2 6 4 10 5 9 5 9 3 10 4 8 4 8
output:
2 2 52 4 14 2 2 16 2 2
result:
ok 10 lines
Test #5:
score: 4
Accepted
time: 0ms
memory: 1120kb
input:
10 20 7 0 2 2 8 12 10 7 1 2 10 9 9 6 9 3 7 3 8 1 6 2 4 6 8 4 5 1 6 8 9
output:
1 2 4 4 4 2 1 1 4 1
result:
ok 10 lines
Test #6:
score: 0
Wrong Answer
time: 0ms
memory: 1136kb
input:
100 20 3 15 11 17 7 9 16 11 6 0 1 1 19 15 18 0 14 12 17 9 19 12 18 9 4 14 11 5 18 10 4 18 14 8 14 8 ...
output:
2 3 52430 2 989896037 1677704 928507060 748745265 107374112 994948534 186027267 104768 1639 71798680...
result:
wrong answer 5th lines differ - expected: '6597996', found: '989896037'
Test #7:
score: 0
Wrong Answer
time: 0ms
memory: 1136kb
input:
100 20 3 7 17 4 9 6 6 15 18 1 3 5 19 13 2 7 9 10 4 5 0 10 18 18 6 0 1 15 16 12 2 7 6 0 17 2 14 18 4 ...
output:
3355488 198 229097541 233638189 753021964 6710976 7 106 8 1677728 6 654999402 1 382278150 802241222 ...
result:
wrong answer 3rd lines differ - expected: '146407370', found: '229097541'
Test #8:
score: 0
Wrong Answer
time: 0ms
memory: 1140kb
input:
100 20 1 11 5 10 8 2 11 14 2 11 7 4 13 4 2 1 13 4 0 13 4 8 3 12 12 17 12 13 16 2 5 12 13 0 5 11 0 7 ...
output:
959584127 10 307958989 307991757 331762287 409 5 214748032 1677728 307273363 307280531 848 2 9949482...
result:
wrong answer 1st lines differ - expected: '26391984', found: '959584127'
Test #9:
score: 0
Wrong Answer
time: 0ms
memory: 1144kb
input:
100 20 8 18 4 8 11 9 1 19 7 14 7 13 4 3 14 0 10 3 13 16 2 5 17 18 7 10 7 3 19 1 16 18 7 13 19 13 2 1...
output:
804 29 26228 214748368 26 406 951162373 107374200 3276 214748736 979792179 102 209724 3355344 419461...
result:
wrong answer 7th lines differ - expected: '144284306', found: '951162373'
Test #10:
score: 0
Wrong Answer
time: 1ms
memory: 1144kb
input:
100 20 17 1 13 11 0 8 12 2 4 15 14 18 6 6 5 16 18 4 6 19 4 0 4 6 10 19 5 4 18 17 14 16 3 0 1 6 2 4 0...
output:
413130607 107374192 743898405 52 3355432 871941334 396 979792067 1 218591847 609295991 8 929408180 4...
result:
wrong answer 1st lines differ - expected: '107223667', found: '413130607'
Test #11:
score: 0
Wrong Answer
time: 0ms
memory: 1312kb
input:
1000 20 7 14 19 15 16 8 19 15 5 5 6 3 4 16 0 1 7 6 14 3 12 2 4 5 16 12 12 8 1 9 6 13 4 10 12 16 11 7...
output:
555495994 29986721 558307492 188353444 757478412 540113850 651478136 419213244 902324019 273622387 2...
result:
wrong answer 1st lines differ - expected: '339309012', found: '555495994'
Test #12:
score: 0
Wrong Answer
time: 3ms
memory: 1312kb
input:
1000 20 16 7 12 15 13 10 8 1 14 16 13 6 16 7 4 11 0 17 6 3 4 8 17 10 3 11 18 13 17 19 15 4 7 17 12 4...
output:
12 707769269 959779170 809013193 157903497 999820507 52381 159477112 258094533 571371796 435481815 2...
result:
wrong answer 2nd lines differ - expected: '484141516', found: '707769269'
Test #13:
score: 0
Wrong Answer
time: 0ms
memory: 1312kb
input:
1000 20 7 7 16 0 12 6 11 3 7 16 12 11 1 7 17 0 11 8 14 17 8 17 7 18 1 11 14 0 6 5 10 0 12 15 1 4 5 1...
output:
91449971 653643341 305784973 951161605 823884729 896221428 432702840 867806685 570467708 153100883 1...
result:
wrong answer 1st lines differ - expected: '425631668', found: '91449971'
Test #14:
score: 0
Wrong Answer
time: 0ms
memory: 1316kb
input:
1000 20 19 3 14 11 9 17 18 4 11 5 0 18 2 11 13 12 8 10 15 19 12 9 2 15 5 19 14 17 17 7 18 5 2 8 5 0 ...
output:
848568579 716838348 716480701 74696958 108294201 270086261 585702235 447037872 497420000 826800170 2...
result:
wrong answer 1st lines differ - expected: '778881096', found: '848568579'
Test #15:
score: 0
Wrong Answer
time: 2ms
memory: 1308kb
input:
1000 20 16 19 4 2 2 19 19 5 11 4 16 7 17 6 11 11 7 10 6 3 15 1 11 12 5 11 12 13 3 10 12 2 19 9 4 8 6...
output:
508457862 519458178 606783924 882261184 633963122 692542977 113180717 554706981 551358430 214722994 ...
result:
wrong answer 1st lines differ - expected: '137484337', found: '508457862'
Test #16:
score: 0
Wrong Answer
time: 17ms
memory: 3012kb
input:
10000 20 12 8 12 19 9 19 1 10 19 11 12 10 19 5 0 16 17 1 9 18 18 13 6 0 14 16 6 6 3 6 17 2 13 19 13 ...
output:
145313515 971058688 425908029 477541288 78058056 420719171 880418794 650899087 610958668 447989719 8...
result:
wrong answer 1st lines differ - expected: '874193350', found: '145313515'
Test #17:
score: 0
Wrong Answer
time: 16ms
memory: 3004kb
input:
10000 20 8 15 6 17 5 13 11 1 7 9 16 16 15 12 4 19 18 2 3 10 13 15 12 5 3 6 15 2 0 11 8 19 13 18 12 1...
output:
386445903 522989898 582213755 660445707 488778454 422657491 97500769 331087127 222791185 140366727 9...
result:
wrong answer 1st lines differ - expected: '11498054', found: '386445903'
Test #18:
score: 0
Wrong Answer
time: 18ms
memory: 3016kb
input:
10000 20 0 9 6 6 17 19 11 13 18 14 0 10 3 0 0 11 12 11 2 19 18 12 13 16 8 7 14 12 10 2 7 3 4 18 10 1...
output:
843235401 423802516 523426547 449795089 820436070 486525233 612812342 44961489 302770349 530265420 1...
result:
wrong answer 1st lines differ - expected: '963045808', found: '843235401'
Test #19:
score: 0
Wrong Answer
time: 19ms
memory: 3012kb
input:
10000 20 5 13 8 2 2 13 16 17 9 8 15 10 1 12 2 18 19 1 0 17 9 7 16 14 0 9 19 14 13 3 19 17 5 3 19 17 ...
output:
697622151 52368562 768588745 608172383 82610217 306468468 280613485 671673135 257860501 928568483 66...
result:
wrong answer 1st lines differ - expected: '875247851', found: '697622151'
Test #20:
score: 0
Wrong Answer
time: 19ms
memory: 3016kb
input:
10000 20 5 8 19 15 4 8 12 14 4 5 16 13 17 9 3 3 15 4 15 19 17 8 14 16 16 13 19 18 19 7 13 5 11 11 12...
output:
48 745715122 360105782 722650678 6767925 46674148 443658305 897011648 677102208 206057722 381146303 ...
result:
wrong answer 2nd lines differ - expected: '749885568', found: '745715122'
Test #21:
score: 0
Wrong Answer
time: 479ms
memory: 39188kb
input:
200000 20 11 5 3 3 2 9 10 10 15 4 19 1 3 0 19 19 15 0 0 12 14 16 1 8 3 18 10 6 14 11 2 7 17 2 0 1 12...
output:
573102532 865999616 104415303 151473615 467501397 399982987 413911681 611764003 252749249 889994675 ...
result:
wrong answer 1st lines differ - expected: '57545307', found: '573102532'
Test #22:
score: 0
Wrong Answer
time: 480ms
memory: 39188kb
input:
200000 20 13 15 5 3 2 0 3 4 6 16 14 0 4 11 8 10 18 5 3 12 1 7 2 16 13 19 16 16 3 16 6 8 2 6 10 0 13 ...
output:
675374851 524713685 174053372 259196432 733013133 583357996 931612012 809714916 55870068 609640803 7...
result:
wrong answer 1st lines differ - expected: '110393808', found: '675374851'
Test #23:
score: 0
Wrong Answer
time: 741ms
memory: 39188kb
input:
200000 20 15 8 8 12 19 10 4 14 16 6 3 17 13 4 14 17 5 15 19 4 0 3 17 5 4 9 14 19 10 11 9 13 0 3 18 0...
output:
187705071 978239692 71821726 431760146 264510379 169527109 443699837 777797420 713750880 984907966 4...
result:
wrong answer 1st lines differ - expected: '218640057', found: '187705071'
Test #24:
score: 0
Wrong Answer
time: 566ms
memory: 39188kb
input:
200000 20 11 4 7 18 16 15 15 18 11 2 4 1 17 18 6 9 19 12 2 14 8 6 10 4 15 16 17 13 18 1 15 18 15 9 1...
output:
166422414 912432086 160045684 778213352 460265301 4274695 54307907 925382565 56984261 620097951 8968...
result:
wrong answer 1st lines differ - expected: '438860874', found: '166422414'
Test #25:
score: 0
Wrong Answer
time: 484ms
memory: 39192kb
input:
200000 20 5 3 18 11 17 13 14 19 0 0 1 3 4 13 8 1 15 7 15 2 12 8 3 15 8 1 4 8 7 5 9 16 9 16 0 14 2 16...
output:
956706283 212033938 507517337 399999850 341608055 706696828 959439168 767661999 54406728 762208230 9...
result:
wrong answer 1st lines differ - expected: '739309565', found: '956706283'