QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#672316#1132. Financial ReportWansur#12 535ms52256kbC++233.1kb2024-10-24 16:26:252024-10-24 16:26:27

Judging History

你现在查看的是最新测评结果

  • [2024-10-24 16:26:27]
  • 评测
  • 测评结果:12
  • 用时:535ms
  • 内存:52256kb
  • [2024-10-24 16:26:25]
  • 提交

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: 0ms
memory: 7640kb

input:

1 1
314159265

output:

1

result:

ok single line: '1'

Test #2:

score: 14
Accepted
time: 0ms
memory: 7640kb

input:

1 1
0

output:

1

result:

ok single line: '1'

Test #3:

score: 14
Accepted
time: 0ms
memory: 7628kb

input:

1 1
1000000000

output:

1

result:

ok single line: '1'

Test #4:

score: 14
Accepted
time: 2ms
memory: 7876kb

input:

2 1
299792458 299792458

output:

1

result:

ok single line: '1'

Test #5:

score: 14
Accepted
time: 2ms
memory: 7632kb

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: 7876kb

input:

2 2
299792458 299792458

output:

1

result:

ok single line: '1'

Test #8:

score: 14
Accepted
time: 2ms
memory: 7732kb

input:

2 2
141421356 173205080

output:

2

result:

ok single line: '2'

Test #9:

score: 14
Accepted
time: 0ms
memory: 7908kb

input:

2 2
244948974 223606797

output:

1

result:

ok single line: '1'

Test #10:

score: 14
Accepted
time: 0ms
memory: 7700kb

input:

3 1
500000000 1000000000 0

output:

2

result:

ok single line: '2'

Test #11:

score: 14
Accepted
time: 1ms
memory: 7688kb

input:

3 2
500000000 1000000000 0

output:

2

result:

ok single line: '2'

Test #12:

score: 14
Accepted
time: 2ms
memory: 7652kb

input:

4 1
0 1000000000 200000000 500000000

output:

2

result:

ok single line: '2'

Test #13:

score: 14
Accepted
time: 2ms
memory: 7732kb

input:

4 2
0 1000000000 200000000 500000000

output:

3

result:

ok single line: '3'

Test #14:

score: 14
Accepted
time: 2ms
memory: 7696kb

input:

5 2
111111111 888888888 555555555 222222222 444444444

output:

2

result:

ok single line: '2'

Test #15:

score: 14
Accepted
time: 2ms
memory: 7636kb

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: 2ms
memory: 7624kb

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: 7628kb

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: 0
Wrong Answer
time: 2ms
memory: 7708kb

input:

20 7
733581184 733581184 0 205928229 0 733581184 1000000000 733581184 0 815970650 975939523 0 815970650 975939523 0 205928229 0 733581184 205928229 815970650

output:

4

result:

wrong answer 1st lines differ - expected: '5', found: '4'

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: 98ms
memory: 28312kb

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: 278ms
memory: 49052kb

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: 398ms
memory: 50064kb

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: 535ms
memory: 50268kb

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: 404ms
memory: 48016kb

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: 526ms
memory: 52256kb

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: 150ms
memory: 48088kb

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: 85ms
memory: 38424kb

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: 172ms
memory: 42452kb

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: 155ms
memory: 45676kb

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: 394ms
memory: 42928kb

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: 446ms
memory: 41952kb

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: 312ms
memory: 48088kb

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: 381ms
memory: 42120kb

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: 89ms
memory: 30076kb

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: 310ms
memory: 47140kb

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:

21

result:

wrong answer 1st lines differ - expected: '85', found: '21'

Subtask #6:

score: 0
Skipped

Dependency #1:

0%