QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#234251#2747. Meetingsjrjyy100 ✓1911ms626036kbC++207.0kb2023-11-01 15:12:002023-11-01 15:12:01

Judging History

This is the latest submission verdict.

  • [2023-11-01 15:12:01]
  • Judged
  • Verdict: 100
  • Time: 1911ms
  • Memory: 626036kb
  • [2023-11-01 15:12:00]
  • Submitted

answer

#include <bits/stdc++.h>

using i64 = long long;

template <typename T, typename Cmp = std::less<T>>
struct RMQ {
    const Cmp cmp;
    int n;
    std::vector<std::vector<T>> a;
    RMQ() = default;
    RMQ(const std::vector<T> &v) : cmp{} {
        init(v);
    }
    RMQ(const std::vector<T> &v, const Cmp &cmp_) : cmp{cmp_} {
        init(v);
    }
    void init(const std::vector<T> &ini) {
        n = int(ini.size());
        int lg = std::__lg(n);
        a.assign(lg + 1, std::vector<T>(n));
        a[0] = ini;
        for (int i = 0; i < lg; ++i) {
            for (int j = 0; j <= n - (2 << i); ++j) {
                a[i + 1][j] = std::min(a[i][j], a[i][j + (1 << i)], cmp);
            }
        }
    }
    T operator()(int l, int r) const {
        int k = std::__lg(r - l);
        return std::min(a[k][l], a[k][r - (1 << k)], cmp);
    }
};

template <typename Info, typename Tag>
struct LazySegmentTree {
    int n;
    std::vector<Info> s;
    std::vector<Tag> t;

    LazySegmentTree() = default;
    LazySegmentTree(int n_, const Info &v = Info{}) {
        init(n_, v);
    }
    template <typename T>
    LazySegmentTree(const std::vector<T> &v) {
        init(v);
    }
    void init(int n_, const Info &v = Info{}) {
        init(std::vector<Info>(n_, v));
    }
    template <typename T>
    void init(const std::vector<T> &v) {
        n = int(v.size());
        s.assign(4 << std::__lg(n), Info{});
        t.assign(4 << std::__lg(n), Tag{});
        auto build = [&](auto self, int u, int l, int r) -> void {
            if (r - l == 1) {
                s[u] = v[l];
                return;
            }
            int m = (l + r) / 2;
            self(self, u << 1, l, m);
            self(self, u << 1 | 1, m, r);
            pull(u);
        };
        build(build, 1, 0, n);
    }

    void pull(int u) {
        s[u] = s[u << 1] + s[u << 1 | 1];
    }
    void apply(int u, const Tag &v) {
        s[u].apply(v);
        t[u].apply(v);
    }
    void push(int u) {
        apply(u << 1, t[u]);
        apply(u << 1 | 1, t[u]);
        t[u] = Tag{};
    }

    void modify(int u, int l, int r, int p, const Info &v) {
        if (r - l == 1) {
            s[u] = v;
            return;
        }
        int m = (l + r) / 2;
        push(u);
        if (p < m) {
            modify(u << 1, l, m, p, v);
        } else {
            modify(u << 1 | 1, m, r, p, v);
        }
        pull(u);
    }
    void modify(int p, const Info &v) {
        modify(1, 0, n, p, v);
    }

    Info query(int u, int l, int r, int p) {
        if (p < l || r <= p) {
            return Info{};
        }
        if (r - l == 1) {
            return s[u];
        }
        int m = (l + r) / 2;
        push(u);
        if (p < m) {
            return query(u << 1, l, m, p);
        } else {
            return query(u << 1 | 1, m, r, p);
        }
    }
    Info query(int p) {
        return query(1, 0, n, p);
    }

    Info rangeQuery(int u, int l, int r, int ql, int qr) {
        if (qr <= l || r <= ql) {
            return Info{};
        }
        if (ql <= l && r <= qr) {
            return s[u];
        }
        int m = (l + r) / 2;
        push(u);
        return rangeQuery(u << 1, l, m, ql, qr) + rangeQuery(u << 1 | 1, m, r, ql, qr);
    }
    Info rangeQuery(int ql, int qr) {
        return rangeQuery(1, 0, n, ql, qr);
    }

    void rangeApply(int u, int l, int r, int ql, int qr, const Tag &v) {
        if (qr <= l || r <= ql) {
            return;
        }
        if (ql <= l && r <= qr) {
            apply(u, v);
            return;
        }
        int m = (l + r) / 2;
        push(u);
        rangeApply(u << 1, l, m, ql, qr, v);
        rangeApply(u << 1 | 1, m, r, ql, qr, v);
        pull(u);
    }
    void rangeApply(int ql, int qr, const Tag &v) {
        rangeApply(1, 0, n, ql, qr, v);
    }
};

struct Tag {
    bool v = false;
    i64 k = 1, b = 0;
    void apply(const Tag &rhs) {
        if (rhs.v) {
            *this = rhs;
        } else {
            std::tie(k, b) = std::pair{k * rhs.k, b * rhs.k + rhs.b};
        }
    }
};
struct Info {
    int l = -1, r = -1;
    i64 vl = 0, vr = 0;
    void apply(const Tag &rhs) {
        if (rhs.v) {
            vl = l;
            vr = r;
        }
        vl = vl * rhs.k + rhs.b;
        vr = vr * rhs.k + rhs.b;
    }
};
Info operator+(const Info &a, const Info &b) {
    return Info{a.l, b.r, a.vl, b.vr};
}

struct DS : LazySegmentTree<Info, Tag> {
    DS(int n, const Info &v = Info{}) : LazySegmentTree(n, v) {}
    void rangeUpdate(int u, int l, int r, int ql, int qr, const Tag &x, const Tag &y) {
        if (qr <= l || r <= ql) {
            return;
        }
        if (ql <= l && r <= qr) {
            Info vx = s[u], vy = s[u];
            vx.apply(x);
            vy.apply(y);
            if (vx.vl <= vy.vl && vx.vr <= vy.vr) {
                apply(u, x);
                return;
            }
            if (vy.vr <= vx.vr && vy.vl <= vx.vl) {
                apply(u, y);
                return;
            }
        }
        int m = (l + r) / 2;
        push(u);
        rangeUpdate(u << 1, l, m, ql, qr, x, y);
        rangeUpdate(u << 1 | 1, m, r, ql, qr, x, y);
        pull(u);
    }
    void rangeUpdate(int ql, int qr, const Tag &x, const Tag &y) {
        rangeUpdate(1, 0, n, ql, qr, x, y);
    }
};

std::vector<i64> minimum_costs(std::vector<int> a, std::vector<int> L, std::vector<int> R) {
    const int n = int(a.size()), q = int(L.size());

    std::vector<int> ord(n);
    std::iota(ord.begin(), ord.end(), 0);
    auto cmp = [&](int x, int y) {
        return std::tie(a[x], x) > std::tie(a[y], y);
    };
    RMQ rmq(ord, cmp);

    std::vector<std::vector<int>> qry(n);
    for (int i = 0; i < q; ++i) {
        int l = L[i], r = R[i], m = rmq(l, r + 1);
        qry[m].push_back(i);
    }

    std::vector<i64> ans(q);
    DS pre(n), suf(n);
    auto query = [&](int l, int m, int r) {
        i64 vl = suf.query(l).vl + 1ll * a[m] * (r - m + 1);
        i64 vr = pre.query(r).vl + 1ll * a[m] * (m - l + 1);
        return std::min(vl, vr);
    };
    auto solve = [&](auto self, int l, int r) -> i64 {
        if (l > r) {
            return 0;
        }
        int m = rmq(l, r + 1);
        i64 vl = self(self, l, m - 1);
        i64 vr = self(self, m + 1, r);
        i64 vm = std::min(vl + 1ll * a[m] * (r - m + 1), vr + 1ll * a[m] * (m - l + 1));
        for (auto id : qry[m]) {
            ans[id] = query(L[id], m, R[id]);
        }

        pre.rangeUpdate(m + 1, r + 1, Tag{true, a[m], vl + 1ll * a[m] * (-m + 1)}, Tag{false, 1, 1ll * a[m] * (m - l + 1)});
        pre.modify(m, Info{m, m, vl + a[m], vl + a[m]});
        suf.rangeUpdate(l, m, Tag{true, -a[m], vr + 1ll * a[m] * (m + 1)}, Tag{false, 1, 1ll * a[m] * (r - m + 1)});
        suf.modify(m, Info{m, m, vr + a[m], vr + a[m]});

        return vm;
    };
    solve(solve, 0, n - 1);

    return ans;
}

详细

Subtask #1:

score: 4
Accepted

Test #1:

score: 4
Accepted
time: 0ms
memory: 3908kb

input:

1 1
877914575
0 0

output:

877914575

result:

ok single line: '877914575'

Test #2:

score: 0
Accepted
time: 3ms
memory: 4444kb

input:

3000 10
24979445 861648772 623690081 433933447 476190629 262703497 211047202 971407775 628894325 731963982 822804784 450968417 430302156 982631932 161735902 880895728 923078537 707723857 189330739 910286918 802329211 404539679 303238506 317063340 492686568 773361868 125660016 650287940 839296263 462...

output:

1024247893897
387722136748
320221738511
62625315028
1243975980128
764186876430
1636726615471
2196212730526
398559935425
1566325595943

result:

ok 10 lines

Test #3:

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

input:

3000 10
117404628 692055095 755070221 715682811 696968512 271712352 785202148 709222314 720911207 502275390 715733144 543795627 209964105 821671150 770596143 206579953 734002701 607943253 52208145 87434096 718162302 537531289 245587594 955642018 846238857 430102181 858054986 214068227 419338432 1679...

output:

2970277257487
2971276731026
2969277783948
2970277127105
2969277653566
2972276074183
2971276600644
2969277914330
2970277387869
2969278044712

result:

ok 10 lines

Test #4:

score: 0
Accepted
time: 3ms
memory: 4272kb

input:

3000 10
802970485 554311944 721586630 658707597 867826691 707711038 1000000000 741016791 163067996 85733395 241003009 725461344 621176293 79025516 623195351 952981317 734991969 493604980 634606367 590654729 183121695 170334116 792844711 683708723 698569581 514638998 455657098 320766092 995695679 329...

output:

776574440162
1356326000564
439271298101
1601904247765
2447904247765
2474904247765
1034054953531
1553381135555
2372904247765
814110055552

result:

ok 10 lines

Test #5:

score: 0
Accepted
time: 3ms
memory: 4380kb

input:

3000 10
89422491 217744789 368590345 897451494 965706806 321471320 945784293 836203774 345208132 644473122 191708254 492559817 265766886 869220009 530285065 308161250 734166493 800351559 893249518 210697945 971033199 486188338 457056803 737363008 179332548 758076441 938993726 145536925 690071016 808...

output:

2980098167942
2982098167942
2983098167942
2980098167942
2982098167942
2981098167942
2981098167942
2980098167942
2981098167942
2980098167942

result:

ok 10 lines

Test #6:

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

input:

3000 10
428861580 1000000000 214980074 1000000000 480956121 1000000000 412622860 1000000000 657131705 1000000000 642915985 1000000000 760418775 1000000000 45825734 1000000000 472385510 1000000000 451586497 1000000000 465087781 1000000000 19418208 1000000000 963358391 1000000000 904958892 1000000000 ...

output:

249013745371
1981001228307
1460001320035
418001320035
404001320035
1024001320035
644002700861
812001320035
265001240575
479008402753

result:

ok 10 lines

Test #7:

score: 0
Accepted
time: 3ms
memory: 4508kb

input:

3000 10
529364148 767311400 683867782 323707782 332212060 346290951 926542051 631784593 61778356 22988053 737593890 932840690 438698802 764173467 918608362 451459958 932832462 536879367 493105063 663232077 605618054 470041452 278845192 788588427 579564762 294283519 138023551 574595496 416322384 2548...

output:

683867782
323707782
529364148
346290951
926542051
61778356
22988053
767311400
631784593
332212060

result:

ok 10 lines

Test #8:

score: 0
Accepted
time: 3ms
memory: 5300kb

input:

3000 10
178531994 178531994 178531994 178531994 178531994 178531994 178531994 178531994 178531994 178531994 178531994 178531994 178531994 178531994 178531994 178531994 178531994 178531994 178531994 178531994 178531994 178531994 178531994 178531994 178531994 178531994 178531994 178531994 178531994 17...

output:

98371128694
98371128694
98371128694
98371128694
98371128694
98371128694
98371128694
98371128694
98371128694
98371128694

result:

ok 10 lines

Test #9:

score: 0
Accepted
time: 3ms
memory: 4684kb

input:

3000 10
4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 ...

output:

2010996
2010996
2008992
2008988
2012000
2008992
2009992
2009996
2009992
2008988

result:

ok 10 lines

Subtask #2:

score: 15
Accepted

Dependency #1:

100%
Accepted

Test #10:

score: 15
Accepted
time: 3ms
memory: 5300kb

input:

5000 5000
925436622 456168989 114729281 417405856 349595598 120468725 364673377 307424567 641054631 862036501 787093000 623030761 774839764 816160008 619531195 260038235 986705026 740332334 975823092 30962247 403533589 933740602 471221917 45689083 21762724 156618421 362146969 568935385 495753848 883...

output:

2661015510739
802634346640
1565937577942
1140494735597
4075185718392
2538372305538
4760000069357
616807306152
2170554898592
1936897102890
1073978985244
1560687367674
1011975758893
2954967032337
1425033550457
520741500207
1493587769205
2230867870289
389522003772
2924272573470
2637924555578
2046508297...

result:

ok 5000 lines

Test #11:

score: 0
Accepted
time: 3ms
memory: 5400kb

input:

5000 5000
84855578 696214291 446408615 796500968 677068585 108017898 522200591 243198052 379722745 30452201 954875002 100979390 190199327 268990073 79983536 699637221 112427957 73817640 678401083 340862503 261149399 100081705 272392427 702820282 891099175 183510481 830066003 435322677 781591370 8534...

output:

4903004865777
4934002746121
4895999182409
4937007280993
4960996171819
4900005106455
4928997637001
4938000955817
4892028156613
4890018031265
4913008471717
4894019914461
4920011583635
4961997193643
4882024550673
4880010751825
4898026205857
4946998029683
4936008095919
4885014391545
4956994655973
493500...

result:

ok 5000 lines

Test #12:

score: 0
Accepted
time: 7ms
memory: 5324kb

input:

5000 5000
811485348 236590243 109563383 813606816 717185667 128178627 169583039 555287367 244224487 344829293 781334370 470010183 290515924 641989951 123436268 641760616 595024436 231947183 487927811 684531018 765780023 427011304 562575887 540591441 627637735 235046977 818996776 579186086 291397338 ...

output:

808321983514
136765682267
3127285371654
396297849181
899924267306
1471280033080
84455182307
3329285371654
3437285371654
123955045957
774200721173
2290285371654
270568060533
182281341845
891193536248
4398285371654
168920995295
141785297818
139094063313
4604285371654
2539285371654
1214354630295
233028...

result:

ok 5000 lines

Test #13:

score: 0
Accepted
time: 6ms
memory: 5524kb

input:

5000 5000
931876096 225147535 626096952 128858237 130347569 337891912 352717960 640399260 616271692 509360777 631828059 461864712 757326267 887437609 232125327 884798262 220102150 787063937 626369548 534678982 463804399 32517840 52079642 691804080 124345362 810255171 183491434 911677637 858286710 36...

output:

4900415980052
4898466858684
4911277880908
4961201562960
4884227002276
4947270612532
4895405077488
4909445053556
4906266978344
4942216099712
4906237904840
4927346930480
4890368735608
4936343296292
4966223368088
4892241539028
4885259709968
4882274246720
4886485029624
4938194294584
4899277880908
491034...

result:

ok 5000 lines

Test #14:

score: 0
Accepted
time: 7ms
memory: 6388kb

input:

5000 5000
150850200 1000000000 268540076 1000000000 230993069 1000000000 111543643 1000000000 271284706 1000000000 804050887 1000000000 738586114 1000000000 157127829 1000000000 940671116 1000000000 201545848 1000000000 68701518 1000000000 774165924 1000000000 177416973 1000000000 859710988 10000000...

output:

2534000755795
2522000755795
38071981088
4163000755795
3442000755795
2351002108553
3505000755795
720002930791
433003190577
124024714923
3302000646604
310002976449
1813002108553
4255000755795
11110952549
1825000755795
756002976449
3130000755795
3545000755795
863002930791
1747002108553
1762000755795
29...

result:

ok 5000 lines

Test #15:

score: 0
Accepted
time: 6ms
memory: 5292kb

input:

5000 5000
103080543 106921177 103080543 385866681 103080543 106921177 103080543 465099713 103080543 106921177 103080543 385866681 103080543 106921177 103080543 718607903 103080543 106921177 103080543 385866681 103080543 106921177 103080543 465099713 103080543 106921177 103080543 385866681 103080543 ...

output:

266516563772
14928842188
1177314071963
1856869788427
258921562404
681288902081
1343557683204
64417629072
2738169394316
705612536726
1277572787035
1328672395409
509942033495
420109881172
771459759181
1104151125461
971292208315
1958412976522
209703799041
1935149894062
1296152663083
3273832058197
41194...

result:

ok 5000 lines

Subtask #3:

score: 17
Accepted

Test #16:

score: 17
Accepted
time: 0ms
memory: 3844kb

input:

1 1
2
0 0

output:

2

result:

ok single line: '2'

Test #17:

score: 0
Accepted
time: 28ms
memory: 8688kb

input:

8014 48643
2 2 1 2 2 1 2 1 1 1 1 1 2 2 1 1 2 1 2 2 1 2 1 1 2 2 2 1 2 1 1 2 1 1 2 1 2 2 1 1 2 2 2 1 1 1 1 2 2 1 1 1 1 1 2 2 2 2 2 2 1 1 2 2 2 1 1 2 1 1 2 2 2 1 2 2 1 1 2 1 1 1 2 1 1 1 1 1 2 2 1 1 2 1 2 2 2 2 2 2 1 2 2 1 2 2 2 1 1 2 1 2 2 1 2 1 1 2 2 2 2 2 2 1 2 2 1 1 1 2 1 1 1 1 2 1 2 2 1 1 1 1 1 1 2...

output:

3556
2463
7389
1531
8055
565
9221
4957
4500
11001
4663
6013
10655
426
331
1495
3961
2197
3543
2786
773
13953
13077
6111
9863
7113
1576
12305
9019
9511
1019
10123
412
8015
13491
9367
7363
2001
5417
8827
361
815
5863
4607
173
6827
5345
5214
3430
2512
11655
3621
9051
290
583
4363
4694
2789
2865
613
464...

result:

ok 48643 lines

Test #18:

score: 0
Accepted
time: 158ms
memory: 63500kb

input:

100000 100000
1 2 1 1 2 1 1 2 2 2 2 1 1 1 2 2 1 1 2 2 2 1 1 2 2 1 2 2 1 2 2 1 1 1 2 2 1 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 2 2 2 2 2 1 2 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 2 2 1 1 1 2 2 1 1 1 2 2 2 2 2 1 1 1 1 2 2 1 1 1 1 1 2 2 1 2 1 2 1 2 2 2 2 2 2 2 1 1 1 1 2 2 2 1 1 2 1 1 1 1 2 2 2 1 1 1 2 2 2 1 1 2 2 1 2 ...

output:

168406
42134
67627
116194
47354
158012
95896
13652
69190
25189
58555
5891
39157
57985
58625
46834
7568
171074
30777
12773
22617
39621
135830
150402
35852
12238
23716
47584
40985
14212
52815
38157
143640
123162
99249
55757
19360
150426
73095
166458
841
90320
77842
10383
191290
20379
115790
134622
474...

result:

ok 100000 lines

Test #19:

score: 0
Accepted
time: 146ms
memory: 43864kb

input:

100000 100000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

15743
57781
66106
101101
36861
31252
10449
79635
92420
165205
146533
139493
39521
12850
137807
41264
58619
114891
26922
158531
14672
75092
23640
50018
50006
6319
4579
2374
88970
185401
102244
57954
54048
62615
29866
85908
129018
82033
95840
26771
14103
53794
61872
1189
95090
36596
29519
38167
41533
...

result:

ok 100000 lines

Test #20:

score: 0
Accepted
time: 156ms
memory: 65512kb

input:

100000 100000
2 2 2 1 2 2 2 1 2 1 2 1 1 2 2 2 2 1 2 2 1 1 2 2 1 1 2 1 1 2 2 2 1 2 1 2 1 2 1 2 2 1 2 2 1 1 1 1 2 1 1 1 2 2 2 2 2 1 1 2 2 2 1 2 1 1 1 2 2 1 1 1 2 1 1 2 1 2 2 2 2 1 2 1 2 2 1 2 1 2 1 2 1 1 1 2 2 1 1 1 1 1 1 1 1 2 2 1 2 1 1 1 2 1 2 2 2 2 1 1 2 1 2 2 1 2 1 2 1 2 1 2 1 2 2 2 2 2 2 2 1 1 1 ...

output:

2
1
1
1
1
1
2
1
1
2
1
2
2
2
1
2
2
2
2
1
1
2
2
1
1
1
1
1
1
2
1
2
2
2
1
2
1
2
2
2
2
1
2
2
2
2
2
1
1
1
1
2
2
1
2
2
1
2
2
2
2
2
1
2
2
1
1
2
1
1
2
1
2
1
2
1
1
2
1
2
1
2
1
1
2
1
2
2
2
2
1
2
2
1
2
2
1
2
1
1
1
1
2
1
2
1
1
2
1
1
1
1
2
2
1
1
1
2
2
1
1
2
1
2
2
2
2
2
1
2
2
1
1
1
1
2
2
2
2
2
2
1
2
2
2
1
2
2
1
1
...

result:

ok 100000 lines

Test #21:

score: 0
Accepted
time: 160ms
memory: 67484kb

input:

100000 100000
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...

output:

551
1102
1102
1102
619
551
551
784
1102
1102
898
1102
615
1102
1102
560
935
1102
1104
1102
1102
551
1102
551
1102
794
1102
765
551
1102
551
801
917
741
1102
1102
1102
1102
551
1047
726
748
1102
1102
551
660
551
1010
1102
551
1102
893
551
848
551
1102
551
1102
1102
551
1102
913
1013
733
575
1102
551
...

result:

ok 100000 lines

Test #22:

score: 0
Accepted
time: 158ms
memory: 73740kb

input:

100000 100000
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...

output:

93072
10048
127454
7287
10697
48837
23960
38279
52605
83423
38556
45086
41906
74620
12478
24472
18593
338
86059
43004
26175
49213
6017
3782
50721
48508
59681
112042
7237
42567
103692
32514
64561
6857
34165
33644
80940
62943
82703
78504
93112
5189
23728
84158
128054
49624
15315
45684
55108
54868
5523...

result:

ok 100000 lines

Subtask #4:

score: 24
Accepted

Dependency #3:

100%
Accepted

Test #23:

score: 24
Accepted
time: 156ms
memory: 45332kb

input:

100000 100000
7 8 10 1 18 12 13 14 17 15 9 5 1 15 15 9 20 15 9 16 11 16 20 13 14 5 20 8 16 12 20 1 12 11 11 5 13 12 17 20 7 2 11 17 15 13 7 14 19 17 14 9 20 20 3 15 2 19 11 17 8 14 16 10 5 13 8 15 8 15 20 4 13 3 7 4 9 18 6 20 2 18 7 4 13 6 3 16 3 4 6 17 12 9 19 2 7 1 6 8 15 20 8 6 19 2 14 5 4 8 2 5 ...

output:

243321
699105
645251
998445
35782
1043118
796231
55270
240059
879491
37347
118783
585805
1554185
436421
496278
994351
188775
604898
1079211
449993
42631
1218305
878411
708938
147618
781638
46004
556585
763825
270450
1136151
761471
602651
419226
483635
288111
1675258
178643
1792498
68762
158291
15841...

result:

ok 100000 lines

Test #24:

score: 0
Accepted
time: 126ms
memory: 45168kb

input:

100000 100000
10 14 1 15 3 17 17 17 12 16 14 4 5 6 9 5 11 13 18 8 20 20 15 10 8 14 12 8 6 17 13 9 16 3 14 19 18 1 14 14 19 15 2 3 12 17 19 3 19 6 19 18 18 7 1 9 9 13 20 8 8 16 16 20 14 8 4 6 11 16 9 6 11 6 6 2 20 4 18 8 9 2 14 19 1 14 16 3 8 7 9 4 19 3 11 15 6 20 12 5 1 6 5 10 16 4 8 19 10 3 19 12 3...

output:

1998416
1991656
1992376
1993696
1997936
1990676
1992916
1997656
1990956
1994616
1991696
1991856
1996576
1991616
1995716
1994916
1995156
1991556
1997056
1991376
1994936
1991396
1994596
1995176
1991436
1992876
1995656
1993696
1994136
1992956
1995556
1995656
1991816
1992116
1992436
1992116
1993736
1992...

result:

ok 100000 lines

Test #25:

score: 0
Accepted
time: 146ms
memory: 45248kb

input:

100000 100000
2 6 19 10 2 3 9 5 15 3 8 12 18 6 16 14 20 1 13 9 4 4 19 1 14 11 9 15 13 17 7 6 18 20 16 14 7 15 5 4 9 20 20 20 15 2 6 11 16 5 9 9 9 9 14 20 17 10 16 19 11 19 11 12 7 10 14 14 1 9 19 7 1 9 13 3 9 10 8 20 19 8 13 16 12 1 6 18 1 12 8 13 2 4 5 4 10 19 2 16 17 11 5 1 10 13 16 6 17 4 4 16 10...

output:

10655
10818
10820
10802
10694
10793
10779
10758
10800
10832
10776
10817
10744
10805
10741
10808
10803
10801
10819
10750
10766
10801
10805
10840
10871
10829
10840
10787
10846
10801
10731
10787
10849
10790
10794
10759
10750
10776
10765
10798
10803
10771
10793
10844
10825
10741
10745
10811
10791
10815
...

result:

ok 100000 lines

Test #26:

score: 0
Accepted
time: 142ms
memory: 43344kb

input:

100000 100000
11 13 11 7 12 13 4 10 15 19 8 16 2 4 11 17 15 12 3 5 17 5 6 6 9 19 7 8 19 10 15 13 6 17 19 11 14 19 17 17 5 8 13 4 13 8 18 2 14 5 9 17 2 17 11 6 6 14 10 18 3 4 7 11 7 16 13 9 6 12 13 5 17 10 3 5 4 13 4 9 13 7 13 7 6 7 16 6 18 10 9 1 5 4 3 1 6 2 3 3 11 13 10 6 12 12 6 17 3 4 8 11 9 4 18...

output:

113723
641767
643306
1394327
14127
374077
1340567
1145808
1133627
63624
1273227
1138867
1892627
236477
754787
747247
1120487
177376
643307
270247
567446
1844227
372268
40902
1369167
16493
913487
267467
1230347
748106
583147
403287
558008
174249
151767
431408
294306
1049726
1297167
1641347
406688
736...

result:

ok 100000 lines

Test #27:

score: 0
Accepted
time: 137ms
memory: 43264kb

input:

100000 100000
8 4 19 14 11 9 14 11 13 14 6 4 13 5 8 19 8 3 5 1 7 8 5 5 13 16 19 8 12 17 17 4 8 1 7 7 8 11 16 1 14 15 11 9 9 3 15 8 18 6 17 6 15 16 13 2 6 14 7 17 16 12 7 1 1 1 12 2 13 5 14 11 1 19 5 2 1 16 8 8 12 3 2 12 6 10 5 10 8 1 1 7 6 18 11 19 10 3 13 12 5 5 10 9 18 18 1 5 18 15 17 17 1 19 16 1...

output:

1991399
1995779
1992499
1990579
1994299
1994779
1991739
1991799
1990799
1990059
1993699
1989839
1993159
1993879
1994359
1993419
1992759
1990579
1993219
1992499
1992019
1989819
1991859
1994879
1993139
1990459
1993059
1992239
1992279
1990359
1996779
1989919
1992779
1993459
1994199
1990439
1992099
1990...

result:

ok 100000 lines

Test #28:

score: 0
Accepted
time: 141ms
memory: 43544kb

input:

100000 100000
6 3 3 12 3 1 18 13 16 6 12 7 6 7 18 11 10 1 12 16 9 17 1 15 4 5 8 2 6 10 17 5 5 1 11 5 6 6 2 11 5 13 12 2 1 8 3 18 9 9 3 1 15 9 8 19 10 12 8 17 12 18 13 18 5 6 19 16 8 17 9 9 9 18 16 13 12 17 7 2 15 4 2 7 11 13 5 14 18 1 7 15 14 8 17 15 16 18 15 6 7 7 11 17 14 14 5 17 2 14 16 13 12 11 ...

output:

10367
10411
10280
10351
10275
10214
10496
10467
10527
10275
10374
10489
10504
10228
10243
10282
10381
10257
10477
10216
10526
10592
10451
10410
10496
10467
10698
10237
10511
10296
10274
10414
10286
10325
10310
10504
10243
10350
10509
10218
10228
10313
10602
10364
10311
10419
10464
10251
10437
10517
...

result:

ok 100000 lines

Test #29:

score: 0
Accepted
time: 148ms
memory: 63660kb

input:

100000 100000
5 20 9 20 2 20 7 20 4 20 17 20 17 20 9 20 18 20 8 20 8 20 18 20 4 20 11 20 4 20 9 20 9 20 15 20 16 20 11 20 7 20 19 20 10 20 12 20 19 20 10 20 2 20 1 20 7 20 18 20 17 20 6 20 9 20 3 20 15 20 2 20 4 20 11 20 5 20 15 20 7 20 12 20 12 20 5 20 4 20 17 20 17 20 6 20 11 20 15 20 8 20 19 20 1...

output:

136041
1167941
580301
1013161
68641
76221
249901
739461
557721
123201
109161
641681
370581
24441
2821
217801
499101
410961
1148341
1475841
16341
299061
452121
372621
304981
629001
1013841
555461
728541
74281
90961
285841
187541
78201
533381
438961
730901
117621
6701
138241
322201
500281
593281
99724...

result:

ok 100000 lines

Test #30:

score: 0
Accepted
time: 134ms
memory: 43252kb

input:

100000 100000
1 3 1 4 1 3 1 5 1 3 1 4 1 3 1 6 1 3 1 4 1 3 1 5 1 3 1 4 1 3 1 7 1 3 1 4 1 3 1 5 1 3 1 4 1 3 1 6 1 3 1 4 1 3 1 5 1 3 1 4 1 3 1 9 1 3 1 4 1 3 1 5 1 3 1 4 1 3 1 6 1 3 1 4 1 3 1 5 1 3 1 4 1 3 1 7 1 3 1 4 1 3 1 5 1 3 1 4 1 3 1 6 1 3 1 4 1 3 1 5 1 3 1 4 1 3 1 10 1 3 1 4 1 3 1 5 1 3 1 4 1 3 1...

output:

594493
21891
136066
14901
362352
1430785
92120
78619
1373505
353177
11259
451359
267146
221147
893565
760065
809737
41289
71392
180716
1474285
4614
1090681
325287
1230207
74257
28343
71639
2074
387057
204139
67515
8607
114331
1184623
492621
42060
1002697
352902
517768
307826
214584
15626
404810
2800...

result:

ok 100000 lines

Test #31:

score: 0
Accepted
time: 177ms
memory: 64420kb

input:

100000 100000
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2...

output:

733598
341699
360933
147599
175299
102961
478159
651063
504872
11746
521051
176907
236575
310738
836332
57325
228885
791978
58636
92172
370867
90193
156328
828905
847477
761251
307086
130750
415023
28328
157241
694102
38996
49861
270586
19812
461934
458189
65182
64018
280725
226364
453058
302084
305...

result:

ok 100000 lines

Subtask #5:

score: 40
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Test #32:

score: 40
Accepted
time: 1572ms
memory: 324436kb

input:

750000 750000
557942945 47871400 553793302 599805251 295392154 31522820 296959980 102434142 936120330 19636535 982046439 327911354 212332123 703511660 920792154 405517949 103634280 965095520 409013836 48488605 197405955 242687973 433575159 558649446 165656176 835877473 108990282 384535032 957687528 ...

output:

51153338402092
130758438656836
385699902314173
314177424882971
301952770257076
82489739057193
67561223403422
106232145889101
25973906986131
28125134389072
45324732428209
211278885094879
80320063308758
301034966305922
128475168562795
60952431362763
365908639817762
143009407065880
134706683349574
1861...

result:

ok 750000 lines

Test #33:

score: 0
Accepted
time: 1196ms
memory: 323188kb

input:

750000 750000
936541133 209689800 501987191 256709938 273062826 273258332 529759531 377094943 377482843 529771200 894292704 419201324 854221187 493307013 527051355 427115229 813795115 835871040 803577352 650627831 786461247 624332043 145050484 704748552 478683406 845131778 518661074 825919196 200637...

output:

748994699186177
749014699897552
748777700356541
748781700068253
749552698827833
748845699456659
749106699570136
748776699599706
749145700684188
749230698802189
749042700837826
749180699673032
748745699326714
749077700693654
748804700917821
749050701169240
749369699729854
749194700184175
748876699009...

result:

ok 750000 lines

Test #34:

score: 0
Accepted
time: 1296ms
memory: 325624kb

input:

750000 750000
542779044 970091839 763420295 911932132 821314598 916569992 470673692 506575957 702842050 524740410 141959944 949520860 307996808 132228047 6454744 663889920 83959327 320310646 583355114 303636281 534943040 256749969 931879923 483426419 690817848 23407416 147620218 625947024 831771498 ...

output:

536824099614
533718886163
532915430167
533773975765
534479785758
530630098569
534179663407
536423438881
533458861437
531779962012
534432273511
537548631219
534643138250
538465275469
533842893414
537210513436
533467115016
527295598204
535439241710
535183457793
533963912730
535400116872
538023790106
5...

result:

ok 750000 lines

Test #35:

score: 0
Accepted
time: 1427ms
memory: 325340kb

input:

750000 750000
912991158 24625336 901055461 834765609 589145236 964728271 424910659 349759631 270274642 388772960 82804671 561273556 336951089 368350848 511102548 561238897 106290020 472072055 976926087 430166457 158064101 7040744 407527114 535475759 262436917 284270471 348539739 514813919 844414861 ...

output:

491466313303122
195206576005487
414887647924518
203807313303122
410252313303122
4359716449363
357845313303122
159694553208538
27808355415985
106248647924518
32757662479615
59617212879018
325151313303122
369570647924518
530759647924518
145725553208538
165453553208538
245354553208538
228472647924518
1...

result:

ok 750000 lines

Test #36:

score: 0
Accepted
time: 1250ms
memory: 325900kb

input:

750000 750000
774247821 508489084 851933980 245020867 485414748 233100178 363748173 160723318 216091371 584487047 409450391 832463871 60215037 207269270 581466390 107252737 366813168 776287274 709003920 971987898 456651900 21738850 575253119 546477331 203121255 443685748 723461924 20634269 807875939...

output:

749214394017889
748774394017889
749483394017889
748989394017889
749245394017889
748803394017889
748758394017889
749271394017889
748879394017889
748853394017889
749382394017889
748998394017889
749161394017889
749165394017889
748795394017889
749669394017889
748809394017889
748762394017889
749428394017...

result:

ok 750000 lines

Test #37:

score: 0
Accepted
time: 1282ms
memory: 326456kb

input:

750000 750000
665042228 563245794 267596668 244305137 483111977 58742857 4652946 687466228 618739766 689193582 496640196 745367776 630855919 37897695 902936556 195839763 627972339 792044144 346011765 942747920 475287645 366775070 719699666 704388227 315132253 160436810 530479886 885510939 533293962 ...

output:

535675822064
534662816880
532665437943
536088193421
537553857420
535307888511
536413283945
533019307418
533374079818
536276530832
536646255067
529000985284
530519745237
538119637868
533414428144
531090976098
536035934843
530480699992
534700045547
535725626611
525285558826
532675514660
538397486606
5...

result:

ok 750000 lines

Test #38:

score: 0
Accepted
time: 1659ms
memory: 475976kb

input:

750000 750000
500196123 1000000000 168049154 1000000000 867098273 1000000000 542457753 1000000000 183763098 1000000000 277150224 1000000000 8293202 1000000000 723417597 1000000000 747536197 1000000000 221976217 1000000000 652058682 1000000000 141290309 1000000000 137874804 1000000000 638024847 10000...

output:

441696000012215
171234000012215
602047000008966
418850000008966
322890000008966
169391000030073
342563000013974
181337000012215
105827000059763
62200000035242
441378000008966
193204000012215
446628000008966
85907000035242
84732000008966
4603000294083
332894000012215
356507000012215
575549000009190
4...

result:

ok 750000 lines

Test #39:

score: 0
Accepted
time: 1742ms
memory: 475984kb

input:

750000 750000
18235 1000000000 55468 1000000000 100139 1000000000 106983 1000000000 113266 1000000000 141191 1000000000 163735 1000000000 286937 1000000000 364847 1000000000 402979 1000000000 539769 1000000000 723298 1000000000 816408 1000000000 1260708 1000000000 1829023 1000000000 1851231 10000000...

output:

460027187363732
226676390479005
196278691060102
181623042906860
279187100485213
278465289813431
327022170440442
434702359805530
621055097034151
189957528148758
120471453401416
338435216452918
20021855702292
607022141483653
18624943821541
412785040048087
274330019667445
265171367543307
32934416230861...

result:

ok 750000 lines

Test #40:

score: 0
Accepted
time: 1444ms
memory: 340328kb

input:

750000 750000
1403 2807 4210 5614 7017 8421 9824 11228 12631 14035 15438 16842 18245 19649 21052 22456 23859 25263 26666 1000000000 28070 29473 30877 32280 33684 35087 36491 37894 39298 40701 42105 43508 44912 46315 47719 49122 50526 51929 53333 999999999 54736 56140 57543 58947 60350 61754 63157 64...

output:

530879940767638
358976998682617
49208262991593
48757906920143
14726913919750
179978194020434
350272167142490
156733407810694
29992524132125
192345460924104
461106137540961
285123493256180
460296028460035
331817848462393
473509345603770
471851461887592
534822754163177
299898089684250
158566863322651
...

result:

ok 750000 lines

Test #41:

score: 0
Accepted
time: 1810ms
memory: 625084kb

input:

750000 750000
999987390 999989632 999984801 999981963 999972950 999972165 999969923 999969078 999968688 999965021 999963806 999961423 999960958 999959916 999957003 999955949 999955716 999948420 999943117 999943071 999939433 999936597 999931943 999930865 999929065 999926888 999922428 999919893 999918...

output:

166366305517528
1913543678
35844779223905
2354739299
1226769792
2311994915
3542455026
3298612128
4542765657
61475347462650
6697096555
166377085508111
53822548928111
2696128079
49369258526064
2572225613
1932204803
7646004027
86246673567028
39109938687704
854919304
276883456630640
188916013512881
1241...

result:

ok 750000 lines

Test #42:

score: 0
Accepted
time: 1911ms
memory: 625876kb

input:

750000 750000
999997849 999999162 999996657 999995950 999992795 999989389 999983667 999982656 999979491 999978206 999978011 999976279 999975895 999972283 999970776 999969921 999967206 999966631 999965994 999960016 999958993 999956740 999949467 999943400 999941753 999935943 999934778 999934732 999927...

output:

58667109061232
111076798099516
63680364299291
7377924095189
38861394637896
83733419601869
182364430891277
202038107851339
13210373629185
19893595660977
72163708082404
45123180830249
67589721385576
171793880853686
68800566624446
80130388429376
57349233956523
181986663431675
17240938731529
10073721996...

result:

ok 750000 lines

Test #43:

score: 0
Accepted
time: 1895ms
memory: 626036kb

input:

750000 750000
999992062 999999234 999988219 999986521 999985023 999983915 999980683 999974597 999966394 999962873 999959046 999959000 999958884 999955682 999955675 999953033 999950945 999943042 999937935 999937274 999931001 999925989 999922297 999922224 999921483 999918339 999912304 999911644 999905...

output:

276777047096929
58108646418758
95829327763323
211653258002571
159611884508369
56539520889132
47258600117583
15769106786437
19681938402485
239716581003502
153679483254499
123506027318322
7153905608920
9734054087850
117066325931338
137285901682319
83907800098823
6116983574053
91204557508816
1358318527...

result:

ok 750000 lines

Test #44:

score: 0
Accepted
time: 1752ms
memory: 476196kb

input:

750000 750000
457872379 999995273 505529296 999992274 425644319 999987020 817483759 999978804 911693549 999972620 781501443 999970563 512154038 999965510 747817779 999960166 337834137 999956593 274968788 999953602 455631132 999939015 771389420 999937782 187186418 999928927 718484144 999927270 534225...

output:

151034118399114
88084789906855
151753611326877
3734992436060
2790050694232
92833016504061
107196664697903
6846981043097
157512345575920
200036831740242
156125492502411
235654426355748
8849978826878
53157285690729
26174364480930
54284657721084
224876612156647
100819185147944
3924176453446
96275920845...

result:

ok 750000 lines

Extra Test:

score: 0
Extra Test Passed