QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#455565#8781. Element-Wise Comparisonmendicillin2#TL 372ms924564kbC++202.1kb2024-06-26 16:24:532024-06-26 16:24:53

Judging History

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

  • [2024-06-26 16:24:53]
  • 评测
  • 测评结果:TL
  • 用时:372ms
  • 内存:924564kb
  • [2024-06-26 16:24:53]
  • 提交

answer

#include <bits/stdc++.h>
#include <ranges>
using namespace std;

template <class T> using Vec = vector<T>;

template <class T, class F> struct QueueAggregation {
    const F f;
    const T e;
    Vec<T> as, bs, ae, be;
    T vs, ve;
    QueueAggregation(F f_, T e_) : f(f_), e(e_), vs(e), ve(e) {}

    void push_s(const T& x) { as.push_back(x), bs.push_back(vs = f(x, vs)); }
    void push_e(const T& x) { ae.push_back(x), be.push_back(ve = f(ve, x)); }
    void reduce() {
        while (!ae.empty()) {
            push_s(ae.back()), ae.pop_back();
        }
        while (!be.empty()) be.pop_back();
        ve = e;
    }

    bool empty() const { return as.empty() && ae.empty(); }
    int size() const { return int(as.size() + ae.size()); }

    void push(const T& x) {
        if (as.empty()) {
            push_s(x), reduce();
        } else {
            push_e(x);
        }
    }
    void pop() {
        assert(!empty());
        if (as.empty()) reduce();
        as.pop_back(), bs.pop_back();
        vs = (bs.empty() ? e : bs.back());
    }
    T prod() const { return f(vs, ve); }
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(20);

    int N, M;
    cin >> N >> M;
    auto P = Vec<int>(N);
    for (int& a : P) {
        cin >> a;
        a--;
    }
    auto invP = Vec<int>(N);
    using views::iota, views::reverse;
    for (int i : iota(0, N)) {
        invP[P[i]] = i;
    }

    constexpr int MAXN = 50010;
    using Bitset = bitset<MAXN>;
    auto larger = Bitset{};
    auto mat = Vec<Bitset>(N);  // mat[i][d] := [P[i] < P[i + d]]
    for (int p : iota(0, N) | reverse) {
        int i = invP[p];
        mat[i] = larger >> i;
        larger.set(i);
    }

    auto all_set = Bitset{};
    all_set.set();
    auto qa = QueueAggregation(
        [](const Bitset& l, const Bitset& r) { return l & r; }, all_set);
    int64_t ans = 0;
    for (int st = 0, en = 0; st + M <= N; st++) {
        while (en - st < M) {
            qa.push(mat[en]);
            en++;
        }
        ans += int(qa.prod().count());
        qa.pop();
    }
    cout << ans << '\n';

    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3612kb

input:

5 3
5 2 1 3 4

output:

0

result:

ok answer is '0'

Test #2:

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

input:

5 2
3 1 4 2 5

output:

2

result:

ok answer is '2'

Test #3:

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

input:

4 2
1 2 3 4

output:

3

result:

ok answer is '3'

Test #4:

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

input:

4 2
4 3 2 1

output:

0

result:

ok answer is '0'

Test #5:

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

input:

1 1
1

output:

0

result:

ok answer is '0'

Test #6:

score: 0
Accepted
time: 226ms
memory: 308936kb

input:

50000 2
44045 29783 5389 7756 44022 45140 21967 5478 10868 49226 21775 31669 49836 13511 46116 14229 27206 31168 37389 3158 10658 41154 14635 18526 40540 6451 23197 46719 30593 13517 8604 46666 39189 43746 12778 3684 3194 36979 43020 14652 19549 31178 17144 27177 44336 2849 40220 11751 41993 32209 4...

output:

310780127

result:

ok answer is '310780127'

Test #7:

score: 0
Accepted
time: 234ms
memory: 308972kb

input:

50000 2
44015 31580 38779 29675 3269 12273 40322 471 4551 44568 21486 17093 43442 11483 9686 39913 36953 47673 34066 4943 28304 34228 9197 43349 1974 32227 8177 33236 24942 42131 34294 48071 17452 9633 18281 13817 27423 9880 15629 6991 20035 13601 39212 33548 8865 39161 48449 22164 36815 28852 43065...

output:

317708201

result:

ok answer is '317708201'

Test #8:

score: 0
Accepted
time: 235ms
memory: 309040kb

input:

50000 2
45828 16955 24033 12988 15675 6086 482 27940 30132 39389 14266 35347 46159 8317 24605 9737 30077 32664 6326 43387 7896 17806 20481 8573 8438 36474 33708 42437 8187 12300 13318 48764 34683 14983 40909 34874 47938 31131 12519 21122 22457 21062 32953 47733 46731 18062 1061 28388 27032 47303 390...

output:

309719539

result:

ok answer is '309719539'

Test #9:

score: 0
Accepted
time: 228ms
memory: 308976kb

input:

50000 2
17900 11121 24441 14321 9486 32843 40283 49359 21526 27801 47381 11444 24372 25999 16187 49470 11724 21419 31873 49053 47656 4516 33567 25021 42444 36150 1362 3711 31260 49923 19998 7275 2927 29522 40437 39439 30777 6413 17107 30917 48362 29997 47038 23951 25835 23665 2875 18889 10610 26400 ...

output:

313258830

result:

ok answer is '313258830'

Test #10:

score: 0
Accepted
time: 226ms
memory: 308936kb

input:

50000 2
29869 3482 18962 41513 1378 27297 29435 6651 12343 3742 27703 32031 15628 16084 12571 1726 30037 31904 2642 817 26607 21749 34528 33044 39980 26798 41826 37079 2809 33387 10169 47346 8551 24214 40572 43065 41730 32281 16630 47892 48890 34159 12884 8185 38452 15606 19304 8428 24230 31397 2232...

output:

313582202

result:

ok answer is '313582202'

Test #11:

score: 0
Accepted
time: 266ms
memory: 309756kb

input:

50000 25
24181 9781 31983 1958 1472 39943 17049 26890 16005 42039 40012 41453 7508 47251 35614 5522 27201 31665 6000 49393 17743 30487 44282 1097 39409 39745 43972 13876 33786 40423 41046 227 44642 27611 9775 21229 48475 7795 32834 15085 44154 45504 26464 45685 42844 44948 26372 30941 8490 8094 4343...

output:

58

result:

ok answer is '58'

Test #12:

score: 0
Accepted
time: 245ms
memory: 309784kb

input:

50000 25
6313 11310 29122 32400 9407 40175 21363 25205 29691 30033 29057 30793 36967 207 521 12478 24585 23970 5059 11072 43604 39890 37153 33289 32907 12925 22807 9811 13003 49978 46897 4643 36366 15146 47056 35036 620 17016 36024 2580 26634 22497 33728 49094 42598 29510 2588 11492 39217 19535 3568...

output:

64

result:

ok answer is '64'

Test #13:

score: 0
Accepted
time: 239ms
memory: 309728kb

input:

50000 25
7101 46567 42238 21041 47850 43080 21835 14601 21483 45662 8296 49277 44528 8471 16934 49649 1159 37986 23124 44670 27253 4997 22785 23185 23498 28808 42277 2373 4953 45403 17687 6448 6646 11865 37061 16908 43882 22053 18899 32888 3268 13484 8282 28369 45369 32118 19979 14248 18913 30053 37...

output:

4

result:

ok answer is '4'

Test #14:

score: 0
Accepted
time: 240ms
memory: 309832kb

input:

50000 25
9582 16768 44838 18085 12760 46386 18931 47470 38877 23660 42553 15072 1132 7328 39756 19422 43849 5886 9208 46852 49509 26185 42588 9415 41859 21884 49608 29541 6265 4552 30506 11148 40872 12019 7531 39615 10614 12159 2888 43822 43634 44176 10373 12227 32929 26749 20475 3280 27429 22261 80...

output:

28

result:

ok answer is '28'

Test #15:

score: 0
Accepted
time: 247ms
memory: 309760kb

input:

50000 25
18777 32602 29569 8351 12443 5109 46381 5184 35720 26389 29442 26751 49739 48691 22692 18229 45132 45826 46500 38936 3677 2482 3508 36713 12096 4589 31302 45887 18816 9740 42267 2275 7538 34775 41814 36968 10986 25755 13093 20616 34034 13055 36066 41746 36775 48968 33860 5503 17541 49741 47...

output:

38

result:

ok answer is '38'

Test #16:

score: 0
Accepted
time: 276ms
memory: 316108kb

input:

50000 250
15070 16717 48256 4440 24276 17592 15337 6219 15845 49955 49002 14123 11954 42720 46986 13584 375 6790 1018 42467 49666 37960 47896 26126 14305 30153 44783 26247 2186 19154 4711 38130 33117 11795 16035 32042 4312 28081 24406 3372 23671 23565 10262 43282 49792 44765 6270 23998 9630 20581 15...

output:

0

result:

ok answer is '0'

Test #17:

score: 0
Accepted
time: 275ms
memory: 316132kb

input:

50000 250
32999 12775 11772 25874 49304 23859 554 48744 41550 21015 2318 34857 5492 43354 48124 3085 26559 18025 19663 27397 8162 7119 40182 48201 19770 485 5753 11213 44460 3938 18529 23936 49880 39625 12123 18411 21408 25086 5584 32740 44856 10184 25518 26410 8154 32863 42006 2765 40280 3683 16878...

output:

0

result:

ok answer is '0'

Test #18:

score: 0
Accepted
time: 277ms
memory: 316144kb

input:

50000 250
22928 47986 35098 8383 11972 22510 8486 41493 48585 30306 9435 34574 29724 32291 40343 46791 8847 25642 29641 48794 16467 20293 6202 40891 16773 13914 41673 27631 27272 22449 37152 37469 19730 12587 31557 22560 33012 10545 47258 34608 42895 9384 20122 29378 8837 1349 35679 20535 4996 46113...

output:

0

result:

ok answer is '0'

Test #19:

score: 0
Accepted
time: 277ms
memory: 316084kb

input:

50000 250
36861 16192 49341 30106 1351 29655 21972 41150 4325 46324 24748 22273 34437 33000 14086 20930 2504 8074 41168 45497 2444 10511 46004 17140 13625 25174 13248 27153 6569 24280 19503 31955 3203 13349 44602 25448 21658 21387 771 35897 25841 27745 23112 17984 16445 1906 34864 14060 11635 12495 ...

output:

0

result:

ok answer is '0'

Test #20:

score: 0
Accepted
time: 283ms
memory: 316184kb

input:

50000 250
44651 6641 40279 35231 28207 38612 11107 8603 25675 23076 7141 23431 343 11668 30231 16527 34195 1024 41033 19519 48977 43258 28563 10844 33945 35736 36086 45052 14706 942 4482 14894 7123 21236 7458 12068 25490 33428 17469 35720 22947 47689 5494 16359 40002 42780 268 11104 26542 22417 4198...

output:

0

result:

ok answer is '0'

Test #21:

score: 0
Accepted
time: 348ms
memory: 400836kb

input:

50000 2500
14379 23426 37565 11703 16722 24713 7259 1881 29688 49717 36901 49493 45629 33419 30112 28361 17058 33589 4037 42664 37380 27768 23738 34164 166 35225 18988 32069 46294 37628 23027 25485 36939 21058 40737 49052 1332 18528 22198 36262 19911 45924 4900 10113 45552 46061 28514 17326 37847 27...

output:

0

result:

ok answer is '0'

Test #22:

score: 0
Accepted
time: 336ms
memory: 399092kb

input:

50000 2500
34466 46827 37369 40822 41757 21791 45039 23502 1637 29443 39698 26205 9914 11396 14596 19891 25353 23638 29323 19571 47715 40389 19546 10792 12694 4208 35713 17709 10527 24365 48513 52 18581 25583 20762 39977 15848 30246 29361 20276 14687 12765 33114 11724 33811 5277 12928 13307 48208 99...

output:

0

result:

ok answer is '0'

Test #23:

score: 0
Accepted
time: 343ms
memory: 400436kb

input:

50000 2500
16387 44292 32179 15229 16111 23270 44569 21074 15098 5503 5964 18419 30808 33950 3494 37647 13919 39187 49055 42252 24329 8633 45329 3530 34620 36074 6500 37302 28358 22693 30416 17738 36875 17209 38721 12312 9692 7203 27276 29496 21174 39100 42609 13039 4220 37160 44153 45312 20685 1495...

output:

0

result:

ok answer is '0'

Test #24:

score: 0
Accepted
time: 365ms
memory: 399680kb

input:

50000 2500
4102 45453 34708 16139 46055 4600 38104 41102 12652 15667 9172 48744 37740 31489 23065 9202 42641 34501 7787 23384 6865 33458 40341 24394 26372 14802 15947 36276 17168 46791 6235 9620 13654 40681 27357 48359 11535 30591 48163 34891 11253 5366 41315 46389 7559 16666 44609 9488 32070 35448 ...

output:

0

result:

ok answer is '0'

Test #25:

score: 0
Accepted
time: 346ms
memory: 399588kb

input:

50000 2500
4765 31823 47392 47212 16690 13390 13886 4988 37389 7491 19944 43362 26775 19065 7291 44609 27418 33124 3071 32379 8783 382 36352 4923 20181 40907 4396 14971 28746 38516 42000 24355 27414 5674 29143 10968 19625 19985 39193 29771 41362 4091 45338 29148 4522 3754 39549 3549 36448 10606 9087...

output:

0

result:

ok answer is '0'

Test #26:

score: 0
Accepted
time: 336ms
memory: 920132kb

input:

50000 25000
27694 17334 36689 31386 31737 11455 45580 24774 10760 22622 38242 46894 7840 25322 5521 12613 26716 22694 25855 25477 10262 35030 44364 20263 32754 25231 12031 41823 11990 23525 42714 4944 2925 21358 13598 43641 11876 15959 32684 33139 19155 32483 16772 19190 24550 37493 41102 8647 43025...

output:

0

result:

ok answer is '0'

Test #27:

score: 0
Accepted
time: 319ms
memory: 921328kb

input:

50000 25000
44016 33666 19414 5385 40981 40283 43975 6878 43709 41524 9656 16710 45770 10732 32635 21865 43523 32271 915 7042 444 48013 36294 3585 49996 11643 30723 25747 31775 48336 45512 2743 44769 47429 8014 41070 34860 12612 36010 5066 17522 17607 30514 20218 36722 6078 41362 29534 15875 819 451...

output:

0

result:

ok answer is '0'

Test #28:

score: 0
Accepted
time: 335ms
memory: 924272kb

input:

50000 25000
18548 21204 2642 29126 38448 36786 49101 3264 21477 17128 37004 32378 18735 11103 30077 21174 13272 30737 40939 35714 47156 25395 42641 37784 14160 13158 2915 21970 15003 30459 6600 25416 32357 21787 17111 40376 46084 22861 26349 22931 2237 32732 39127 44963 42881 28344 40191 14685 19692...

output:

0

result:

ok answer is '0'

Test #29:

score: 0
Accepted
time: 323ms
memory: 923444kb

input:

50000 25000
22121 42962 46051 15480 12670 30302 22927 17242 44174 42743 7178 38964 38129 7628 2635 5306 46715 25681 21768 46091 27793 42640 28882 49382 35390 8446 22138 39030 49880 24709 47386 32262 32593 1504 27202 48926 36461 49843 21448 43765 49673 22056 46947 30717 36240 25518 2203 47976 15589 1...

output:

0

result:

ok answer is '0'

Test #30:

score: 0
Accepted
time: 329ms
memory: 924564kb

input:

50000 25000
47178 27280 8198 29160 42916 17772 3807 9479 28530 40842 14551 22877 22211 42763 32510 20330 8487 29401 26704 17104 5333 13770 47756 20854 19189 15916 29033 16839 6232 23354 40868 42924 34479 17258 46011 14427 17459 2554 15183 1180 48545 19727 3564 8595 25540 36694 30257 44394 44697 2319...

output:

0

result:

ok answer is '0'

Test #31:

score: 0
Accepted
time: 336ms
memory: 492608kb

input:

50000 5000
28664 2202 4603 43800 48905 42109 58 42500 21591 47108 11450 6559 35633 35340 13056 11028 4188 19273 12825 40269 22606 23648 5139 42220 25096 3308 9965 20194 34538 48726 46563 906 9760 46427 33404 38054 38836 39368 13694 34190 35151 10770 22820 46972 12138 14786 45427 21867 14653 11867 35...

output:

0

result:

ok answer is '0'

Test #32:

score: 0
Accepted
time: 363ms
memory: 490428kb

input:

50000 5000
29415 37254 9292 31856 41439 34899 22705 31140 30432 23050 37463 35062 44740 24799 26133 39208 28790 29172 5022 16087 34463 33542 35094 16472 42457 43738 12812 34489 47293 45111 43790 45092 9540 23669 1570 43499 16422 33732 43122 2075 15955 15793 35557 43733 40264 1775 20689 49630 11587 2...

output:

0

result:

ok answer is '0'

Test #33:

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

input:

50000 5000
38880 22972 10057 47774 15305 12835 8303 17916 14134 17253 47251 16436 25464 44971 33072 48580 47147 14940 47850 42030 30418 45836 36064 39346 23684 12724 48715 34149 30366 27796 17909 22444 7986 28074 42026 49066 25787 15821 26491 38515 24089 13199 33267 11781 49712 42488 26609 9586 4299...

output:

0

result:

ok answer is '0'

Test #34:

score: 0
Accepted
time: 365ms
memory: 491232kb

input:

50000 5000
22449 29725 11386 16002 34512 41050 24506 9207 36171 41312 39817 49794 3924 41805 3468 30231 5775 22611 46871 37970 26396 13401 21 32708 35911 34805 2148 22066 32607 26830 19557 31091 35170 26601 35364 26093 47433 5860 26267 23293 27191 3335 42192 45844 28406 5534 12885 44842 30431 11492 ...

output:

0

result:

ok answer is '0'

Test #35:

score: 0
Accepted
time: 344ms
memory: 491568kb

input:

50000 5000
40286 46980 1220 4024 40563 14448 44762 14878 46266 29127 42561 36990 24660 15985 30945 46078 24628 32792 37946 33334 3323 11866 35170 21734 9244 35772 47527 19295 47033 16672 21165 2186 3132 17458 9616 22782 13141 5175 35664 12735 40606 10905 47122 2808 14525 47739 4544 30038 46090 3920 ...

output:

0

result:

ok answer is '0'

Test #36:

score: 0
Accepted
time: 348ms
memory: 587052kb

input:

50000 10000
18902 3060 40220 12119 24070 29001 35075 25657 3771 37564 16283 7897 5711 47444 11653 11978 15679 28838 23910 16563 25241 45894 42485 35925 46940 11284 49773 33624 34936 7510 4265 48370 40939 12246 4558 36443 23492 4458 5694 23282 13256 25146 13642 2296 17563 22633 3740 9031 26848 6931 3...

output:

0

result:

ok answer is '0'

Test #37:

score: 0
Accepted
time: 372ms
memory: 583368kb

input:

50000 10000
28890 38404 18861 30686 18213 41445 22538 14435 23423 39590 34671 37639 10966 35644 10983 43436 10579 3531 19846 25162 13473 1753 9074 18852 7641 26945 5243 39948 35012 39397 267 45511 43576 12311 43901 37209 16809 17730 37526 1327 10080 25165 9888 30527 20594 4332 5487 24449 35328 48519...

output:

0

result:

ok answer is '0'

Test #38:

score: -100
Time Limit Exceeded

input:

50000 10000
13084 29539 36846 10537 27833 8757 12233 43657 33794 33488 5878 28799 12399 265 45667 37867 43778 17157 8899 13668 25893 15436 13081 38071 33659 29373 30493 45114 49640 21641 46498 30252 18369 22877 20302 46346 36391 12491 32210 42482 45559 36208 33206 1612 7203 33361 11448 2000 21227 40...

output:

0

result: