QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#584009 | #1913. Non-Decreasing Subsequences | makrav | 8.333333 | 204ms | 14224kb | C++20 | 3.5kb | 2024-09-23 03:38:47 | 2024-09-23 03:38:48 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define pb push_back
#define ff first
#define sc second
const int mod = 1e9 + 7;
struct fenwick {
int n;
vector<int> t;
fenwick() = default;
fenwick(int n_) {
n = n_;
t.assign(n + 1, 0);
}
void clear() {
t.assign(n + 1, 0);
}
void upd(int p, int vl) {
for (; p <= n; p = (p | (p + 1))) {
t[p] += vl;
if (t[p] >= mod) t[p] -= mod;
}
}
int get(int p) {
int sm = 0;
for (; p > 0; p = (p & (p + 1)) - 1) {
sm += t[p];
if (sm >= mod) sm -= mod;
}
return sm;
}
};
void solve() {
int n, k; cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int q; cin >> q;
vector<vector<pair<int, int>>> qrs(n);
vector<int> answ(q);
for (int i = 0; i < q; i++) {
int l, r; cin >> l >> r;
l--; r--;
qrs[l].pb({r, i});
}
for (int i = 0; i < n; i++) sort(all(qrs[i]));
vector<vector<int>> dp(n, vector<int>(k + 1));
vector<fenwick> fw_right(k + 1), fw_left(k + 1);
for (int i = 1; i <= k; i++) {
fw_right[i] = fenwick(k + 2);
fw_left[i] = fenwick(k + 2);
}
auto solve = [&](int l, int r, auto&&self) -> void {
if (l + 1 == r) {
for (auto &u : qrs[l]) {
answ[u.second] = 2;
}
qrs[l].clear();
return;
}
int tm = (l + r) / 2;
for (int i = 1; i <= k; i++) {
fw_right[i].clear(); fw_left[i].clear();
}
for (int i = tm; i < r; i++) {
for (int j = 1; j <= a[i]; j++) {
fw_right[j].upd(a[i], fw_right[j].get(a[i]));
if (j == a[i]) fw_right[j].upd(a[i], 1);
}
for (int j = 1; j <= k; j++) dp[i][j] = fw_right[j].get(k);
}
for (int i = tm - 1; i >= l; i--) {
for (int j = a[i]; j <= k; j++) {
fw_left[j].upd(a[i], (fw_left[j].get(k) - fw_left[j].get(a[i] - 1) + mod) % mod);
if (j == a[i]) fw_left[j].upd(a[i], 1);
}
for (int j = 1; j <= k; j++) dp[i][j] = fw_left[j].get(k);
}
for (int i = l; i < tm; i++) {
while (!qrs[i].empty() && qrs[i].back().first < r) {
int rg = qrs[i].back().first;
ll sm = 0, ans = 1;
for (int j = 1; j <= k; j++) {
ans += dp[rg][j] + dp[i][j];
ans %= mod;
sm += dp[i][j];
if (sm >= mod) sm -= mod;
ans += dp[rg][j] * 1ll * sm;
ans %= mod;
}
answ[qrs[i].back().second] = ans;
qrs[i].pop_back();
}
}
self(l, tm, self);
self(tm, r, self);
};
solve(0, n, solve);
for (auto &u : answ) cout << u << '\n';
}
signed main() {
int tt = 1;
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
cin >> tt;
#else
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
#endif
while (tt--) {
solve();
}
return 0;
}
詳細信息
Pretests
Final Tests
Test #1:
score: 8.33333
Accepted
time: 0ms
memory: 3552kb
input:
5 2 1 2 1 1 2 3 2 3 4 5 1 5
output:
3 4 20
result:
ok 3 lines
Test #2:
score: 0
Wrong Answer
time: 193ms
memory: 14224kb
input:
50000 20 1 5 20 6 15 5 4 17 6 16 20 13 2 18 17 2 16 12 12 3 1 10 13 1 14 12 14 2 8 2 3 20 7 2 17 13 18 20 9 15 16 20 7 9 18 3 3 5 6 14 7 18 15 19 18 9 2 12 10 10 5 12 1 3 5 18 8 2 9 16 8 16 8 15 17 5 9 19 9 15 12 7 4 7 17 2 15 19 5 16 20 9 19 20 4 3 9 11 16 10 18 3 5 5 17 1 1 18 11 9 4 3 7 7 1 4 20 ...
output:
818003058 709308075 475289676 415943700 511824150 455839879 747395419 268449204 917031643 198441968 129596950 353314365 170696961 574814568 906036189 187186333 217464521 843247167 916480518 575784105 688746070 417861366 941292174 559529951 940484342 355107074 57308513 891388603 421506431 190972981 5...
result:
wrong answer 1st lines differ - expected: '648477307', found: '818003058'
Test #3:
score: 0
Wrong Answer
time: 204ms
memory: 14120kb
input:
50000 20 12 10 2 6 1 3 11 11 13 20 3 16 20 16 13 18 3 19 18 18 1 15 16 7 9 9 3 9 15 15 20 6 16 13 11 16 15 13 19 19 4 1 7 4 8 11 1 11 9 19 20 9 5 15 7 13 3 9 13 9 15 4 6 11 9 16 18 15 1 16 14 4 8 12 19 16 2 20 6 10 10 17 18 14 11 16 18 6 4 10 14 11 13 20 1 1 7 18 16 19 6 1 15 13 12 13 20 5 4 17 14 5...
output:
441862540 165855921 152121532 218847643 348659462 930810332 596041005 546055644 621900602 668060866 397078714 624145385 103992940 775940115 785271782 460904463 61136626 362573347 768155221 904034223 805760997 682955530 532231925 330197447 218319508 763061602 954923976 25923568 708181202 216696971 86...
result:
wrong answer 1st lines differ - expected: '510482945', found: '441862540'
Test #4:
score: 0
Wrong Answer
time: 193ms
memory: 14124kb
input:
50000 20 16 12 3 14 15 20 3 16 13 10 12 10 20 14 17 2 12 8 20 6 7 4 12 15 14 13 5 7 11 3 3 6 6 17 12 20 16 14 16 8 4 19 17 15 4 6 16 15 13 8 12 12 3 4 18 16 8 2 3 18 16 17 4 1 14 15 12 9 20 7 9 3 17 17 10 1 2 17 7 7 4 19 18 6 14 7 14 1 20 8 19 15 4 14 7 9 20 18 10 19 17 10 14 13 6 3 5 20 19 4 6 15 1...
output:
637280489 941157822 33609909 125839953 146855331 195571649 647639429 464782428 877922167 421978279 369125367 632145315 895106108 474699246 364650445 703830242 64907787 126094797 383513922 941027223 747020019 597930975 25887143 898619117 209568131 13187279 81333330 960299284 251746829 38769217 830658...
result:
wrong answer 2nd lines differ - expected: '777647513', found: '941157822'
Test #5:
score: 0
Wrong Answer
time: 45ms
memory: 6824kb
input:
1000 20 15 3 13 7 4 11 8 18 3 3 2 18 11 5 15 16 4 19 7 6 11 18 11 11 8 16 13 1 3 12 19 17 6 4 15 10 6 3 19 8 17 20 17 7 16 11 14 20 1 13 5 11 10 7 14 9 2 6 10 4 9 20 12 15 15 7 16 20 9 14 19 17 6 15 3 1 18 9 20 10 13 4 1 2 3 14 11 4 11 12 20 19 3 3 13 18 9 8 9 9 14 8 5 19 14 20 11 3 20 11 13 12 6 5 ...
output:
555039665 176770531 560591791 101471548 395410675 395324111 580373931 368893440 556162762 417419291 879344857 298266518 19667 867351892 925782209 497110043 853825146 772589306 496811961 65190126 188690115 264459167 178769505 307685655 479926157 704574735 7827678 315953773 954154912 691043331 7425382...
result:
wrong answer 9th lines differ - expected: '359763866', found: '556162762'
Test #6:
score: 0
Wrong Answer
time: 61ms
memory: 6832kb
input:
1000 20 4 5 7 12 5 3 1 4 18 6 4 6 15 14 12 10 17 3 15 16 2 20 9 6 11 1 17 16 20 20 2 15 17 20 18 13 14 11 8 11 16 12 16 3 17 19 4 14 13 19 9 6 10 9 12 12 1 20 8 13 11 1 19 19 20 17 4 5 19 11 16 6 14 3 8 11 14 12 16 18 2 16 4 3 5 7 14 17 6 13 9 8 13 8 7 4 16 10 9 6 12 16 11 6 10 11 8 3 14 3 1 15 18 4...
output:
819635573 701434646 150277213 193440777 705323452 60579366 400425019 202468556 970028331 35910130 843673923 490613192 520180080 309079579 412052877 878987465 672894209 267175144 352802987 759595352 965145667 75206219 194007189 570610140 24210 60646 859868916 566833936 750949117 752745841 75185131 11...
result:
wrong answer 2nd lines differ - expected: '684463864', found: '701434646'
Test #7:
score: 0
Wrong Answer
time: 79ms
memory: 10720kb
input:
50000 5 5 5 1 4 4 4 2 3 3 1 1 1 4 2 2 2 5 5 5 4 4 4 4 1 4 3 2 1 5 1 1 4 2 1 4 1 1 5 5 3 2 1 5 2 4 3 4 5 3 3 3 1 3 3 3 1 5 5 4 4 2 1 4 4 1 4 1 3 1 5 1 2 2 2 4 5 5 2 2 2 1 1 4 3 4 2 1 3 3 1 4 1 1 4 1 3 3 1 5 3 3 2 1 4 4 4 1 5 2 2 3 4 2 3 2 2 1 4 5 3 4 5 1 1 3 1 3 2 4 4 1 3 3 2 1 1 2 3 2 1 1 4 4 5 1 2 ...
output:
102164314 350235475 50430881 58553338 486403711 396281836 83504360 744595167 104045529 598712931 291565563 270526435 955445488 785809339 794303445 622577532 495503624 560783327 823758497 419546112 417179464 528757891 535313386 445329148 689310788 413256231 244200595 606351612 307164049 940646417 202...
result:
wrong answer 1st lines differ - expected: '926368451', found: '102164314'
Test #8:
score: 0
Wrong Answer
time: 85ms
memory: 10788kb
input:
50000 5 4 4 5 3 5 1 3 1 4 3 4 4 5 5 5 5 4 2 3 2 3 2 3 2 4 3 2 4 5 1 3 5 1 3 3 5 5 2 2 3 1 2 1 3 4 3 2 2 4 1 3 1 2 2 2 5 5 5 1 1 2 3 1 2 2 5 4 3 3 2 3 1 1 5 3 4 2 1 5 2 3 4 4 1 5 5 3 1 2 3 2 3 2 4 2 1 5 5 3 2 3 5 2 3 5 1 1 1 3 2 3 5 5 1 3 2 3 5 2 1 2 3 5 5 3 1 5 2 2 3 4 5 4 2 2 3 5 5 1 2 1 3 4 3 5 1 ...
output:
582094526 931361388 623268062 709503251 707917231 768261646 31984116 921665556 859282338 581915790 821773372 672631454 836301852 524825254 911593900 562403578 244789113 32810324 700929067 499171738 354997588 320066096 777656563 694819447 451044055 591335093 281783663 931313910 923396138 164209317 40...
result:
wrong answer 1st lines differ - expected: '125103175', found: '582094526'
Test #9:
score: 0
Wrong Answer
time: 86ms
memory: 10736kb
input:
50000 5 3 5 4 1 5 5 3 3 2 4 2 3 2 2 5 1 2 4 2 3 2 5 4 3 5 3 2 4 1 1 4 5 2 3 2 3 2 5 1 3 5 4 2 1 5 2 3 3 5 4 1 3 5 1 5 4 5 1 2 5 3 3 2 1 5 5 4 1 4 4 4 5 4 5 2 1 1 4 3 2 4 5 4 3 2 3 4 2 1 2 3 3 4 4 4 3 4 4 4 4 2 4 1 2 5 2 2 1 3 2 4 1 1 3 1 5 2 4 1 2 2 3 2 1 4 2 3 4 5 3 4 3 3 1 4 3 5 1 3 2 4 3 4 1 5 4 ...
output:
338257176 978394415 252587310 266546179 161131305 172075136 926864802 886823611 791172584 994479418 728461801 134672914 995767856 511028207 529304694 528751264 745140235 740428981 427940420 957764946 861001883 863947505 328285398 829406067 974529203 121739378 664288219 574262555 294932256 575275572 ...
result:
wrong answer 5th lines differ - expected: '528286984', found: '161131305'
Test #10:
score: 0
Wrong Answer
time: 154ms
memory: 12444kb
input:
50000 20 16 13 12 19 15 8 19 11 4 15 20 20 14 10 16 4 6 6 17 5 7 5 16 16 5 14 13 6 6 5 10 1 9 2 12 3 1 10 5 16 16 16 15 9 5 2 12 2 19 20 6 5 17 13 20 1 18 4 7 4 8 8 16 16 1 19 10 1 20 14 16 16 9 10 16 5 3 8 6 1 19 4 5 15 8 17 8 6 20 14 1 8 13 8 15 14 7 17 14 18 2 10 13 11 11 1 7 14 20 5 14 18 8 19 5...
output:
247419772 488598582 357447310 530616125 94359467 970360547 846926326 968762927 993816575 191737403 684013086 307561338 241119757 997210175 761974780 217360525 557327215 145034662 106561318 306387719 735161239 711234619 400910479 283964834 193092636 930483973 77361018 105582934 60202734 887109671 413...
result:
wrong answer 2nd lines differ - expected: '269688019', found: '488598582'
Test #11:
score: 0
Wrong Answer
time: 152ms
memory: 12276kb
input:
50000 20 1 6 13 1 6 5 16 8 4 17 18 15 5 18 15 12 14 2 18 13 13 17 9 15 3 19 15 15 2 16 11 14 13 15 6 18 11 1 5 14 17 14 8 14 4 14 5 9 16 14 2 8 11 2 14 5 1 1 19 2 16 1 7 8 15 12 17 5 13 13 10 1 6 18 14 1 3 11 10 18 4 3 17 6 4 11 2 4 11 12 17 18 12 3 17 18 7 13 14 11 5 4 11 2 13 17 15 15 19 4 5 2 6 1...
output:
181383728 943344466 673369756 18875755 28201656 474124464 404624158 56176157 757711165 478822482 839872586 321059651 743053093 679231486 141925591 126795047 50860462 609562836 943152539 500223075 795565296 371095172 657942105 498689953 64923137 852854856 155664038 185960813 462173248 485817040 79503...
result:
wrong answer 4th lines differ - expected: '24865496', found: '18875755'
Test #12:
score: 0
Wrong Answer
time: 157ms
memory: 12336kb
input:
50000 20 14 1 16 11 11 6 19 10 20 4 17 3 13 19 13 11 4 18 16 17 16 1 18 16 18 6 13 2 4 15 19 17 15 15 20 6 12 10 7 3 5 3 5 17 2 18 19 5 7 14 1 3 14 10 10 3 16 14 5 19 8 3 7 3 9 18 20 12 7 6 15 11 9 11 19 2 20 18 6 7 3 18 1 17 7 2 19 14 16 15 12 15 10 11 9 18 8 8 2 7 14 16 9 14 6 8 15 18 17 12 16 19 ...
output:
921338517 536588631 62408692 120188081 400183659 194233503 20020660 628595471 670862894 947800396 167677407 625911507 872818410 834308020 363412739 855417795 304208073 220247805 670120090 111875044 19283371 490849538 901546174 113507952 842758295 769623098 348609770 623256525 869434687 986815016 901...
result:
wrong answer 3rd lines differ - expected: '173949831', found: '62408692'