QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#672477 | #1132. Financial Report | Wansur# | 12 | 543ms | 52336kb | C++23 | 3.1kb | 2024-10-24 16:58:42 | 2024-10-24 16:58:43 |
Judging History
answer
#include <bits/stdc++.h>
#define ent '\n'
#define int long long
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 12;
const int mod = 998244353;
vector<int> g[maxn];
int t[maxn * 4];
int R[maxn];
int dp[maxn];
int a[maxn];
int n, m, k;
void upd(int v, int tl, int tr, int pos, int x) {
if(tl == tr) {
t[v] = x;
return;
}
int mid = tl + tr >> 1;
if(pos <= mid) {
upd(v * 2, tl, mid, pos, x);
}
else {
upd(v * 2 + 1, mid + 1, tr, pos, x);
}
t[v] = max(t[v * 2], t[v * 2 + 1]);
}
int get(int v, int tl, int tr, int l, int r) {
if(tl > r || l > tr) return 0;
if(tl >= l && tr <= r) return t[v];
int mid = tl + tr >> 1;
return max(get(v * 2, tl, mid, l, r), get(v * 2 + 1, mid + 1, tr, l, r));
}
void solve() {
cin >> n >> k;
vector<int> ord;
for(int i = 1; i <= n; i++) {
cin >> a[i];
ord.push_back(a[i]);
}
sort(ord.begin(), ord.end());
ord.resize(unique(ord.begin(), ord.end()) - ord.begin());
vector<int> p;
for(int i = 1; i <= n; i++) {
p.push_back(i);
a[i] = lower_bound(ord.begin(), ord.end(), a[i]) - ord.begin() + 1;
}
sort(p.begin(), p.end(), [](int i, int j) {
if(a[i] == a[j]) return i > j;
return a[i] < a[j];
});
set<pair<int, int>> s, bg;
s.insert({n, 1});
bg.insert({n, 1});
auto add = [&](int l, int r) -> void {
s.insert({r, l});
if(r - l + 1 >= k) {
bg.insert({r, l});
}
};
auto update = [&](int x) -> void {
auto [r, l] = *s.lower_bound({x, 0});
s.erase({r, l});
bg.erase({r, l});
if(x < r) {
add(x + 1, r);
}
if(x > l) {
add(l, x - 1);
}
};
for(int i : p) {
update(i);
auto it = bg.lower_bound({i, 0});
if(it == bg.end()) {
R[i] = n + 1;
}
else {
R[i] = it -> second + k - 1;
}
auto nxt = s.lower_bound({i, 0});
if(nxt != s.end()) {
g[nxt -> second].push_back(i);
}
}
vector<int> v;
int ans = 0;
for(int i = n; i; i--) {
dp[i] = max(dp[i], 1ll);
ans = max(ans, dp[i]);
while(v.size() && a[v.back()] > a[i]) {
upd(1, 1, n, v.back(), 0);
v.pop_back();
}
upd(1, 1, n, i, dp[i]);
v.push_back(i);
for(int j : g[i]) {
int pos = v.size() - 1;
for(int l = 0, r = v.size() - 1; l <= r;) {
int mid = l + r >> 1;
if(a[v[mid]] > a[j] && v[mid] <= R[j]) {
pos = mid;
r = mid - 1;
}
else l = mid + 1;
}
dp[j] = get(1, 1, n, i, v[pos]) + 1;
}
}
cout << ans << '\n';
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
while(t--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 14
Accepted
time: 2ms
memory: 7708kb
input:
1 1 314159265
output:
1
result:
ok single line: '1'
Test #2:
score: 14
Accepted
time: 0ms
memory: 7588kb
input:
1 1 0
output:
1
result:
ok single line: '1'
Test #3:
score: 14
Accepted
time: 2ms
memory: 7588kb
input:
1 1 1000000000
output:
1
result:
ok single line: '1'
Test #4:
score: 14
Accepted
time: 2ms
memory: 7720kb
input:
2 1 299792458 299792458
output:
1
result:
ok single line: '1'
Test #5:
score: 14
Accepted
time: 2ms
memory: 7592kb
input:
2 1 141421356 173205080
output:
2
result:
ok single line: '2'
Test #6:
score: 14
Accepted
time: 2ms
memory: 7700kb
input:
2 1 244948974 223606797
output:
1
result:
ok single line: '1'
Test #7:
score: 14
Accepted
time: 2ms
memory: 7860kb
input:
2 2 299792458 299792458
output:
1
result:
ok single line: '1'
Test #8:
score: 14
Accepted
time: 0ms
memory: 7704kb
input:
2 2 141421356 173205080
output:
2
result:
ok single line: '2'
Test #9:
score: 14
Accepted
time: 0ms
memory: 7696kb
input:
2 2 244948974 223606797
output:
1
result:
ok single line: '1'
Test #10:
score: 14
Accepted
time: 2ms
memory: 7704kb
input:
3 1 500000000 1000000000 0
output:
2
result:
ok single line: '2'
Test #11:
score: 14
Accepted
time: 0ms
memory: 7712kb
input:
3 2 500000000 1000000000 0
output:
2
result:
ok single line: '2'
Test #12:
score: 14
Accepted
time: 0ms
memory: 7652kb
input:
4 1 0 1000000000 200000000 500000000
output:
2
result:
ok single line: '2'
Test #13:
score: 14
Accepted
time: 2ms
memory: 7720kb
input:
4 2 0 1000000000 200000000 500000000
output:
3
result:
ok single line: '3'
Test #14:
score: 14
Accepted
time: 2ms
memory: 7720kb
input:
5 2 111111111 888888888 555555555 222222222 444444444
output:
2
result:
ok single line: '2'
Test #15:
score: 14
Accepted
time: 0ms
memory: 7884kb
input:
19 1 876813783 876813783 294665595 1000000000 515198511 876813783 876813783 294665595 403855901 439947219 439947219 403855901 581007064 294665595 1000000000 581007064 294665595 865289906 865289906
output:
5
result:
ok single line: '5'
Test #16:
score: 14
Accepted
time: 0ms
memory: 7628kb
input:
17 2 49121102 449215299 18829293 449463830 765492419 440501697 233785699 50699732 569054461 105188844 983737936 877900994 0 44809615 361020433 74987201 725464354
output:
5
result:
ok single line: '5'
Test #17:
score: 14
Accepted
time: 2ms
memory: 7632kb
input:
15 3 807337796 807337796 807337796 807337796 807337796 807337796 807337796 807337796 807337796 807337796 807337796 807337796 807337796 807337796 807337796
output:
1
result:
ok single line: '1'
Test #18:
score: 14
Accepted
time: 2ms
memory: 7652kb
input:
20 7 733581184 733581184 0 205928229 0 733581184 1000000000 733581184 0 815970650 975939523 0 815970650 975939523 0 205928229 0 733581184 205928229 815970650
output:
5
result:
ok single line: '5'
Test #19:
score: 14
Accepted
time: 2ms
memory: 7640kb
input:
18 12 1000000000 358612551 1000000000 358612551 358612551 358612551 358612551 1000000000 1000000000 1000000000 358612551 358612551 1000000000 1000000000 358612551 1000000000 1000000000 358612551
output:
2
result:
ok single line: '2'
Test #20:
score: 14
Accepted
time: 2ms
memory: 7596kb
input:
20 20 802421546 601860856 909073419 815745406 913824895 924761528 954389636 774128549 427176220 23722581 439396497 59191904 121848351 774320268 817458024 565828491 890339952 82761751 717137276 524535907
output:
6
result:
ok single line: '6'
Test #21:
score: 14
Accepted
time: 2ms
memory: 7940kb
input:
20 2 220907318 325117564 759996279 361226977 713619929 530965981 367577457 488411054 555070688 620059582 541892208 949650763 645304844 727718360 709566813 803811825 110264462 960815323 875849635 450666865
output:
10
result:
ok single line: '10'
Test #22:
score: 14
Accepted
time: 2ms
memory: 7924kb
input:
20 4 920699809 20405458 430167187 323905322 321816206 337791282 869436958 505338540 45509543 532042224 672842133 816481120 854290279 948611594 979068279 996148973 674793874 347773693 320013346 759492294
output:
11
result:
ok single line: '11'
Test #23:
score: 14
Accepted
time: 2ms
memory: 7716kb
input:
20 1 10000000 60000000 110000000 160000000 210000000 260000000 310000000 360000000 410000000 460000000 510000000 560000000 610000000 660000000 710000000 760000000 810000000 860000000 910000000 960000000
output:
20
result:
ok single line: '20'
Test #24:
score: 14
Accepted
time: 2ms
memory: 7636kb
input:
20 1 970000000 920000000 870000000 820000000 770000000 720000000 670000000 620000000 570000000 520000000 470000000 420000000 370000000 320000000 270000000 220000000 170000000 120000000 70000000 20000000
output:
1
result:
ok single line: '1'
Test #25:
score: 0
Wrong Answer
time: 2ms
memory: 7728kb
input:
16 5 68514423 410103741 591567982 865691960 982387008 223996512 306149309 324123848 352045607 927590130 238419389 252822214 452213108 539870292 860882612 965882206
output:
8
result:
wrong answer 1st lines differ - expected: '9', found: '8'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 12
Accepted
Test #62:
score: 12
Accepted
time: 66ms
memory: 34688kb
input:
300000 1 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 2...
output:
1
result:
ok single line: '1'
Test #63:
score: 12
Accepted
time: 293ms
memory: 52336kb
input:
299971 1 213313757 312061773 790195557 213313757 0 790195557 30936680 832403554 312061773 30936680 0 213313757 329317874 329317874 0 0 329317874 329317874 0 213313757 329317874 790195557 832403554 832403554 329317874 312061773 832403554 832403554 329317874 329317874 312061773 790195557 790195557 790...
output:
7
result:
ok single line: '7'
Test #64:
score: 12
Accepted
time: 430ms
memory: 48568kb
input:
299964 1 999391533 795527538 725929353 340564009 761636306 1000000000 266904585 105958508 549383838 340564009 431998269 141078858 236783723 651207509 554129129 514310143 802266954 185376130 366537845 883789079 688298181 621545068 692525271 555960625 415080461 468820678 149895819 709946893 415080461 ...
output:
15
result:
ok single line: '15'
Test #65:
score: 12
Accepted
time: 543ms
memory: 51636kb
input:
300000 1 548117244 559216957 507201469 40534874 269192764 516346951 183733704 869745777 781914589 551408564 699975473 735567843 438862496 240429620 67594019 153803925 72746062 343276550 121453383 412576614 208627475 771041507 950354624 832001069 221477371 192349583 674402432 552830114 73583781 83795...
output:
27
result:
ok single line: '27'
Test #66:
score: 12
Accepted
time: 397ms
memory: 48676kb
input:
300000 1 691596759 196814375 574002903 594314532 982102853 676133704 51798090 506287024 603831698 332571699 178065016 71628067 59716653 762524657 554265870 950792677 301567670 821363269 109779474 783340951 247333489 525773395 351088520 438229302 527706457 82894430 867332858 179925618 508622616 66518...
output:
884
result:
ok single line: '884'
Test #67:
score: 12
Accepted
time: 532ms
memory: 51424kb
input:
300000 1 508573390 653912933 525806709 842004427 840728278 229089762 812466273 74713576 264668073 60014628 114629166 490347940 65502437 978210434 145920485 2253440 570123282 966368812 123749349 598895954 650307775 739167010 695523885 568813226 673823768 163707323 266177084 902827760 68463107 2067017...
output:
103
result:
ok single line: '103'
Test #68:
score: 12
Accepted
time: 147ms
memory: 47016kb
input:
298001 1 0 3000 6000 9000 12000 15000 18000 21000 24000 27000 30000 33000 36000 39000 42000 45000 48000 51000 54000 57000 60000 63000 66000 69000 72000 75000 78000 81000 84000 87000 90000 93000 96000 99000 102000 105000 108000 111000 114000 117000 120000 123000 126000 129000 132000 135000 138000 141...
output:
298001
result:
ok single line: '298001'
Test #69:
score: 12
Accepted
time: 72ms
memory: 39692kb
input:
299000 1 1000000000 999997000 999994000 999991000 999988000 999985000 999982000 999979000 999976000 999973000 999970000 999967000 999964000 999961000 999958000 999955000 999952000 999949000 999946000 999943000 999940000 999937000 999934000 999931000 999928000 999925000 999922000 999919000 999916000 ...
output:
1
result:
ok single line: '1'
Test #70:
score: 12
Accepted
time: 154ms
memory: 42204kb
input:
300000 1 51267 48487 51734 58209 66692 65845 71175 71732 83572 79254 83251 84629 87645 94230 94738 100344 109931 112084 109549 113351 119313 127359 123183 126791 128597 137279 141116 149449 140623 148493 149407 162451 157006 167247 165547 165108 173471 171258 179567 178965 180527 191627 193481 19801...
output:
199817
result:
ok single line: '199817'
Test #71:
score: 12
Accepted
time: 145ms
memory: 45352kb
input:
300000 1 999954124 999961493 999949571 999940534 999946372 999925293 999921072 999931534 999929095 999921784 999918158 999912773 999912775 999907080 999901635 999906959 999895997 999914791 999898797 999887896 999886196 999879293 999878173 999860009 999870934 999862029 999856087 999870137 999855763 9...
output:
6
result:
ok single line: '6'
Test #72:
score: 12
Accepted
time: 403ms
memory: 41972kb
input:
300000 1 55790207 24851814 5936441 5673060 10133935 26545446 6192893 19286522 1039500 10348355 18571272 21565109 2707724 2645056 7768362 16168158 30490652 14472735 41080293 17329687 29499736 27215909 1570578 20363064 29573893 15689924 2964459 38913136 3086679 27953900 5577610 9113792 8417327 2795942...
output:
173
result:
ok single line: '173'
Test #73:
score: 12
Accepted
time: 434ms
memory: 47044kb
input:
300000 1 986224645 973290423 921165567 942477463 990040077 973659018 993652908 957835882 900146494 991231459 916204391 995878673 940086940 984600081 948674214 939427627 982916850 936106236 905592641 995543085 991453079 927386355 873454036 929562047 975674525 959756113 960251352 996473311 940368512 9...
output:
24
result:
ok single line: '24'
Test #74:
score: 12
Accepted
time: 317ms
memory: 46736kb
input:
300000 1 1074087 1395268 3277962 4530953 7048294 8442637 9391344 10199114 10556943 10873532 10954804 12009054 12203474 12877543 13677744 14068323 14499068 14748767 15532706 16080395 16439403 16639545 17139008 17485645 18247183 20479594 22874753 24727837 24902867 25239038 25411476 26015570 26210533 2...
output:
1347
result:
ok single line: '1347'
Test #75:
score: 12
Accepted
time: 384ms
memory: 41812kb
input:
300000 1 988050337 978814479 951726265 944396353 940609759 923184414 913787618 910930128 903521243 878390362 873253523 858528019 843354656 841931158 836360030 815304982 794519954 790267809 772866477 770579401 742214422 734000478 713784823 586112422 580474117 560105339 556897652 551354844 537217385 5...
output:
19
result:
ok single line: '19'
Subtask #5:
score: 0
Wrong Answer
Test #76:
score: 5
Accepted
time: 71ms
memory: 38684kb
input:
300000 300000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 ...
output:
1
result:
ok single line: '1'
Test #77:
score: 0
Wrong Answer
time: 315ms
memory: 48432kb
input:
299994 299994 799095588 515641284 851040998 371590609 581412250 114983578 870953189 65883574 114983578 546636247 675572999 416143410 763181943 799095588 564152084 521371792 455808474 799095588 870953189 839155298 684313832 605076527 675572999 219704773 684313832 372618560 875093839 41381734 11498357...
output:
22
result:
wrong answer 1st lines differ - expected: '85', found: '22'
Subtask #6:
score: 0
Skipped
Dependency #1:
0%