QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#454319#1132. Financial Reportmakrav19 421ms45620kbC++203.2kb2024-06-24 19:25:452024-06-24 19:25:45

Judging History

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

  • [2024-06-24 19:25:45]
  • 评测
  • 测评结果:19
  • 用时:421ms
  • 内存:45620kb
  • [2024-06-24 19:25:45]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

struct segtree {
    int n;
    vector<int> t;
    segtree() = default;
    segtree(int n_) {
        n = n_;
        t.assign(4 * n, 0);
    }

    void upd(int v, int tl, int tr, int p, int vl) {
        if (tl + 1 == tr) {
            t[v] = vl;
            return;
        }
        int tm = (tl + tr) / 2;
        if (p < tm) upd(v * 2, tl, tm, p, vl);
        else upd(v * 2 + 1, tm, tr, p, vl);
        t[v] = max(t[v * 2], t[v * 2 + 1]);
    }

    int get(int v, int tl, int tr, int l, int r) {
        if (l <= tl && tr <= r) return t[v];
        if (tr <= l || tl >= r) return 0;
        int tm = (tl + tr) / 2;
        return max(get(v * 2, tl, tm, l, r), get(v * 2 + 1, tm, tr, l, r));
    }

    int getr(int v, int tl, int tr, int p, int vl) {
        if (tr <= p || t[v] <= vl) return -1;
        if (tl + 1 == tr) return tl;
        int tm = (tl + tr) / 2;
        int answ = getr(v * 2, tl, tm, p, vl);
        if (answ == -1) return getr(v * 2 + 1, tm, tr, p, vl);
        return answ;
    }
};

signed main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    int n, d; cin >> n >> d;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    vector<int> ord(n);
    for (int i = 0; i < n; i++) ord[i] = i;
    sort(ord.begin(), ord.end(), [&](int i, int j) {
        return a[i] < a[j];
    });
    
    vector<int> pos(n);
    for (int i = 0; i < n; i++) pos[ord[i]] = i;
    vector<int> prv(n, 0);
    prv[ord[0]] = -1;
    for (int i = 1; i < n; i++) {
        if (a[ord[i]] == a[ord[i - 1]]) prv[ord[i]] = prv[ord[i - 1]];
        else prv[ord[i]] = i - 1;
    }
    set<int> st;
    segtree sg_x(n);
    auto add = [&](int i) {
        auto it = st.lower_bound(i);
        int prv = -1, nxt = -1;
        if (it != st.end()) {
            nxt = *it;
        }
        st.insert(i);
        if (st.find(i) != st.begin()) {
            auto it2 = --st.find(i);
            prv = *it2;
        }
        if (nxt == -1) {
            sg_x.upd(1, 0, n, i, 1e9);  
        } else{
            sg_x.upd(1, 0, n, i, nxt - i);
        }
        if (prv != -1) {
            sg_x.upd(1, 0, n, prv, i - prv);
        }
    };
    vector<int> x(n);
    int cur = 0;
    for (int i = 1; i < n; i++) {
        if (prv[ord[i]] == i - 1) {
            for (int j = cur; j < i; j++) {
                add(ord[j]);
            }
            for (int j = cur; j < i; j++) {
                int ans = sg_x.getr(1, 0, n, ord[j], d);
                if (ans == -1) x[j] = n;
                else x[j] = ans;
            }
            cur = i;
        }
    }
    segtree sg(n);
    vector<int> dp(n);
    vector<vector<int>> del(n);
    for (int i = 0; i < n; i++) {
        for (auto &u : del[i]) {
            sg.upd(1, 0, n, pos[u], 0);
        }
        if (prv[i] == -1) dp[i] = 1;
        else {
            dp[i] = sg.get(1, 0, n, 0, prv[i] + 1) + 1;
        }
        sg.upd(1, 0, n, pos[i], dp[i]);
        if (x[i] + d + 1 < n) del[x[i] + d + 1].push_back(pos[i]);
    }
    int mx = 0;
    for (int i = 0; i < n; i++) mx = max(mx, dp[i]);
    cout << mx << '\n';
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 14
Accepted

Test #1:

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

input:

1 1
314159265

output:

1

result:

ok single line: '1'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3440kb

input:

1 1
0

output:

1

result:

ok single line: '1'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3444kb

input:

1 1
1000000000

output:

1

result:

ok single line: '1'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3580kb

input:

2 1
299792458 299792458

output:

1

result:

ok single line: '1'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3552kb

input:

2 1
141421356 173205080

output:

2

result:

ok single line: '2'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3736kb

input:

2 1
244948974 223606797

output:

1

result:

ok single line: '1'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3584kb

input:

2 2
299792458 299792458

output:

1

result:

ok single line: '1'

Test #8:

score: 0
Accepted
time: 0ms
memory: 3580kb

input:

2 2
141421356 173205080

output:

2

result:

ok single line: '2'

Test #9:

score: 0
Accepted
time: 0ms
memory: 3800kb

input:

2 2
244948974 223606797

output:

1

result:

ok single line: '1'

Test #10:

score: 0
Accepted
time: 0ms
memory: 3616kb

input:

3 1
500000000 1000000000 0

output:

2

result:

ok single line: '2'

Test #11:

score: 0
Accepted
time: 0ms
memory: 3592kb

input:

3 2
500000000 1000000000 0

output:

2

result:

ok single line: '2'

Test #12:

score: 0
Accepted
time: 0ms
memory: 3448kb

input:

4 1
0 1000000000 200000000 500000000

output:

2

result:

ok single line: '2'

Test #13:

score: 0
Accepted
time: 0ms
memory: 3432kb

input:

4 2
0 1000000000 200000000 500000000

output:

3

result:

ok single line: '3'

Test #14:

score: 0
Accepted
time: 0ms
memory: 3528kb

input:

5 2
111111111 888888888 555555555 222222222 444444444

output:

2

result:

ok single line: '2'

Test #15:

score: 0
Accepted
time: 0ms
memory: 3584kb

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: 0
Accepted
time: 0ms
memory: 3736kb

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: 0
Accepted
time: 0ms
memory: 3740kb

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
Accepted
time: 0ms
memory: 3732kb

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: 0
Accepted
time: 0ms
memory: 3584kb

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: 0
Accepted
time: 0ms
memory: 3588kb

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: 0
Accepted
time: 0ms
memory: 3584kb

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: 0
Accepted
time: 0ms
memory: 3800kb

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: 0
Accepted
time: 0ms
memory: 3444kb

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: 0
Accepted
time: 0ms
memory: 3524kb

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
Accepted
time: 0ms
memory: 3428kb

input:

16 5
68514423 410103741 591567982 865691960 982387008 223996512 306149309 324123848 352045607 927590130 238419389 252822214 452213108 539870292 860882612 965882206

output:

9

result:

ok single line: '9'

Test #26:

score: 0
Accepted
time: 0ms
memory: 3704kb

input:

17 4
22790108 220864673 248053769 404589265 637574960 166412775 260226295 262479043 286448651 300001992 734205739 58675918 181211505 263369364 299892200 509157732 867133240

output:

9

result:

ok single line: '9'

Subtask #2:

score: 0
Wrong Answer

Dependency #1:

100%
Accepted

Test #27:

score: 0
Wrong Answer
time: 1ms
memory: 3480kb

input:

400 1
697625071 338955244 701273756 765293932 12805194 46984119 775140965 390552579 875281333 950702147 361444232 680144638 917418512 747923326 543035419 899203308 659270340 218742714 484689980 866434940 270117732 538163289 665365203 226080481 734351408 300250974 824534838 56953777 250622631 4998775...

output:

34

result:

wrong answer 1st lines differ - expected: '15', found: '34'

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Wrong Answer

Test #62:

score: 12
Accepted
time: 45ms
memory: 28608kb

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: 0
Accepted
time: 266ms
memory: 43260kb

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
Wrong Answer
time: 421ms
memory: 45620kb

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:

114

result:

wrong answer 1st lines differ - expected: '15', found: '114'

Subtask #5:

score: 5
Accepted

Test #76:

score: 5
Accepted
time: 44ms
memory: 26432kb

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
Accepted
time: 356ms
memory: 40632kb

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:

85

result:

ok single line: '85'

Test #78:

score: 0
Accepted
time: 385ms
memory: 40648kb

input:

299967 299967
55436237 815265051 726638198 232614559 766667170 589412354 222916094 881505795 351969379 185039621 500722663 929961726 12106126 527589224 131615979 740414875 483735803 961030961 685115515 630631167 847411283 606876236 853479813 969869770 978153478 951567612 284079913 655441675 23301827...

output:

1000

result:

ok single line: '1000'

Test #79:

score: 0
Accepted
time: 387ms
memory: 40708kb

input:

300000 300000
501796523 297945585 927399536 440670566 495542465 80848196 28003478 540869900 992383926 48799286 967913195 572970230 215873915 538679144 853459893 70385046 947090071 440258092 348827388 912684078 519842448 805256446 548573509 148406683 373586707 74817790 975254107 599779344 939526125 4...

output:

1079

result:

ok single line: '1079'

Test #80:

score: 0
Accepted
time: 352ms
memory: 40480kb

input:

300000 300000
863887522 425397042 713124005 773467613 489882500 437277345 139704179 557800941 215336895 161026143 927354002 294297768 165771354 512842947 537130652 175822358 136551779 148723787 79361863 416871734 644501573 743434372 557135739 94545556 438248865 141290994 550236652 94773186 137640908...

output:

119010

result:

ok single line: '119010'

Test #81:

score: 0
Accepted
time: 400ms
memory: 40540kb

input:

300000 300000
261069220 62324615 942003105 79398536 881237922 660291668 342301327 287380444 258811488 67001231 625514902 572229121 938217290 244331276 295213680 418810760 250148739 681986353 93691086 258512344 334478574 842247076 289652772 232932429 900601662 770838744 512730335 879450985 799339736 ...

output:

4195

result:

ok single line: '4195'

Test #82:

score: 0
Accepted
time: 267ms
memory: 40632kb

input:

300000 300000
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 13800...

output:

300000

result:

ok single line: '300000'

Test #83:

score: 0
Accepted
time: 217ms
memory: 40592kb

input:

300000 300000
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 99991...

output:

1

result:

ok single line: '1'

Test #84:

score: 0
Accepted
time: 190ms
memory: 40536kb

input:

298001 298001
34832 79106 92233 41187 22866 85580 32085 65715 113345 78332 61133 129921 63730 69451 73358 152855 121615 76292 134438 105458 81917 6956 78765 162590 107750 159413 169971 115829 134528 131661 75589 115759 143187 97623 223499 186250 151499 168707 105513 236574 176390 103994 237829 22505...

output:

87419

result:

ok single line: '87419'

Test #85:

score: 0
Accepted
time: 289ms
memory: 40480kb

input:

299000 299000
21957810 19402999 14174232 1584658 23477964 9979277 9164532 22323998 21003307 7443362 11819189 14661748 5803988 13596735 14666310 13535681 6460845 4003025 22441699 11909961 17684693 22096644 3463574 10789456 23133078 971943 20299903 1829387 6699896 17730801 1731607 17750814 7072208 903...

output:

4790

result:

ok single line: '4790'

Test #86:

score: 0
Accepted
time: 377ms
memory: 40528kb

input:

300000 300000
18367526 39162436 46248746 53023958 58166604 60555798 128617672 154424917 171357763 178047421 179307707 186820325 216560886 238860292 244781586 284718360 288356348 337385547 341190169 345812663 352395427 353945030 361546670 367410573 386805472 420176531 495081945 500301991 502134964 51...

output:

1124

result:

ok single line: '1124'

Test #87:

score: 0
Accepted
time: 288ms
memory: 40644kb

input:

300000 300000
998504892 998265952 997934075 997214275 997098713 996128339 995808017 995445379 994380027 994042007 994039412 993364233 993318976 992223668 991102126 990845586 987858596 987274453 986989530 986543852 986441325 986249054 986094401 985671270 985225560 984404578 984003136 983470456 983176...

output:

225

result:

ok single line: '225'

Subtask #6:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%