QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#124008#6675. DS Team Selection 2batrr#AC ✓405ms89480kbC++1710.3kb2023-07-14 03:39:432023-07-14 03:39:45

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-14 03:39:45]
  • 评测
  • 测评结果:AC
  • 用时:405ms
  • 内存:89480kb
  • [2023-07-14 03:39:43]
  • 提交

answer

#include <bits/stdc++.h>

#define f first
#define s second
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int N = 200500, inf = 1e9, mod = 998244353;
const ll INF = 1e18;

int sum(int a, int b) {
    a += b;
    if (a >= mod)
        a -= mod;
    return a;
}

int sub(int a, int b) {
    a -= b;
    if (a < 0)
        a += mod;
    return a;
}

int mult(int a, int b) {
    return 1ll * a * b % mod;
}

int bp(int a, int b) {
    int res = 1;
    while (b) {
        if (b & 1)
            res = mult(res, a);
        a = mult(a, a);
        b >>= 1;
    }
    return res;
}

int inv(int x) {
    return bp(x, mod - 2);
}

int n, q;
const int maxN = 2e5 + 10;
ll a[maxN];
int tp[maxN];
int l[maxN], r[maxN];
ll v[maxN];
ll b[maxN], c[maxN];
int frst[maxN];

vector<int> g_frst[N];

namespace PRE_SEG {
    int cnt;
    ll t1[N << 2], t2[N << 2];

    void build(int v, int tl, int tr) {
        if (tl == tr) {
            t1[v] = a[tl];
            t2[v] = tl;
            return;
        }
        int tm = (tl + tr) >> 1;
        build(v << 1, tl, tm);
        build(v << 1 | 1, tm + 1, tr);
        t1[v] = t1[v << 1] + t1[v << 1 | 1];
        t2[v] = t2[v << 1] + t2[v << 1 | 1];
    }

    void upd(int v, int tl, int tr, int p) {
        if (tl == tr) {
            t1[v] = t2[v] = 0;
            return;
        }
        int tm = (tl + tr) >> 1;
        if (p <= tm)
            upd(v << 1, tl, tm, p);
        else
            upd(v << 1 | 1, tm + 1, tr, p);
        t1[v] = t1[v << 1] + t1[v << 1 | 1];
        t2[v] = t2[v << 1] + t2[v << 1 | 1];
    }

    pll get(int v, int tl, int tr, int l, int r) {
        if (r < tl || tr < l || l > r)
            return {0, 0};
        if (l <= tl && tr <= r)
            return {t1[v], t2[v]};
        int tm = (tl + tr) >> 1;
        pll a = get(v << 1, tl, tm, l, r);
        pll b = get(v << 1 | 1, tm + 1, tr, l, r);
        return {a.f + b.f, a.s + b.s};
    }

    ll get(int l, int r) {
        pll res = get(1, 1, n, l, r);
        return res.f + res.s * cnt;
    }
};
namespace AFTER_SEG {
    ll cnt[N << 2];
    ll t1[N << 2], tc[N << 2];
    ll t2[N << 2];
    ll mx1[N << 2], mx2[N << 2];
    ll mn1[N << 2], mn2[N << 2];

    ll lazy[N << 2];

    void build(int v, int tl, int tr) {
        cnt[v] = 0;
        tc[v] = 0;

        t1[v] = t2[v] = 0;
        mx1[v] = mx2[v] = 0;
        mn1[v] = mn2[v] = 0;
        lazy[v] = -1;

        if (tl == tr)
            return;
        int tm = (tl + tr) >> 1;
        build(v << 1, tl, tm);
        build(v << 1 | 1, tm + 1, tr);
    }

    void pull(int v) {
        cnt[v] = 0;
        tc[v] = 0;
        t1[v] = t2[v] = 0;
        mn1[v] = mn2[v] = INF;
        mx1[v] = mx2[v] = -INF;
        lazy[v] = -1;
        for (auto u: {v << 1, v << 1 | 1}) {
            if (cnt[u] == 0)
                continue;
            cnt[v] += cnt[u];
            t1[v] += t1[u];
            t2[v] += t2[u];
            mn1[v] = min(mn1[v], mn1[u]);
            mn2[v] = min(mn2[v], mn2[u]);
            mx1[v] = max(mx1[v], mx1[u]);
            mx2[v] = max(mx2[v], mx2[u]);
        }
    }

    void push(int v) {
        if (lazy[v] != -1) {
            for (auto u: {v << 1, v << 1 | 1}) {
                if (cnt[u] == 0)
                    continue;
                lazy[u] = lazy[v];
                tc[u] = 0;
                t1[u] = cnt[u] * lazy[u];
                mn1[u] = lazy[u];
                mx1[u] = lazy[u];
            }
            lazy[v] = -1;
        }
        if (tc[v] != 0) {
            for (auto u: {v << 1, v << 1 | 1}) {
                if (cnt[u] == 0)
                    continue;
                tc[u] += tc[v];
                t1[u] += t2[u] * tc[v];
                mn1[u] += mn2[u] * tc[v];
                mx1[u] += mx2[u] * tc[v];
            }
            tc[v] = 0;
        }
    }

    void add(int v, int tl, int tr, int p, ll x) {
        if (tl == tr) {
            cnt[v] = 1;
            tc[v] = 0;
            t1[v] = mn1[v] = mx1[v] = x;
            t2[v] = mn2[v] = mx2[v] = p;
            lazy[v] = -1;
            return;
        }
        push(v);
        int tm = (tl + tr) >> 1;
        if (p <= tm)
            add(v << 1, tl, tm, p, x);
        else
            add(v << 1 | 1, tm + 1, tr, p, x);
        pull(v);
    }

    void upd(int v, int tl, int tr, ll x) {
        if (cnt[v] == 0)
            return;
        if (mx1[v] <= x)
            return;
        if (mn1[v] >= x) {
            lazy[v] = x;
            tc[v] = 0;
            mn1[v] = mx1[v] = x;
            t1[v] = cnt[v] * x;
            return;
        }
        push(v);
        int tm = (tl + tr) >> 1;
        upd(v << 1, tl, tm, x);
        upd(v << 1 | 1, tm + 1, tr, x);
        pull(v);
    }

    ll get(int v, int tl, int tr, int l, int r) {
        if (r < tl || tr < l || l > r)
            return 0;
        if (l <= tl && tr <= r)
            return t1[v];
        push(v);
        int tm = (tl + tr) >> 1;
        return get(v << 1, tl, tm, l, r) + get(v << 1 | 1, tm + 1, tr, l, r);
    }

    void upd() {
        if (cnt[1] == 0)
            return;
        tc[1]++;
        t1[1] += t2[1];
        mn1[1] += mn2[1];
        mx1[1] += mx2[1];
    }
};

void calc(int l, int r, vector<int> &INDS) {
    if (INDS.empty() || l > r) return;
    if (l == r) {
        for (int u: INDS) {
            if (tp[l] == 1) {
                if (b[u] > v[l]) frst[u] = l;
                else frst[u] = q + 1;
            }
        }
        return;
    }
    vector<pair<ll, ll>> lines;
    int cnt = 0;
    int MID = (l + r) / 2;
    for (int i = MID; i >= l; i--) {
        if (tp[i] == 2) {
            cnt++;
        } else if (tp[i] == 1) {
            if (!lines.empty() && lines.back().first == cnt) {
                if (lines.back().second <= v[i]) continue;
                lines.pop_back();
            }
            if (!lines.empty()) {
                assert(lines.back().first < cnt);
            }
            while ((int) lines.size() >= 2 &&
                   (cnt - lines.back().first) * (lines[lines.size() - 1].second - lines[lines.size() - 2].second)
                   > (lines[lines.size() - 1].first - lines[lines.size() - 2].first) * (v[i] - lines.back().second)) {
                lines.pop_back();
            }
            lines.emplace_back(cnt, v[i]);
        }
    }
    auto get_mn = [&](ll pt) {
        if (lines.empty()) return (ll) 1e18;
        int l = -1;
        int r = lines.size() - 1;
        while (r - l > 1) {
            int mid = (l + r) / 2;
            if (lines[mid].first * pt + lines[mid].second > lines[mid + 1].first * pt + lines[mid + 1].second) {
                l = mid;
            } else {
                r = mid;
            }
        }
        return lines[r].first * pt + lines[r].second;
    };
    vector<int> INDS_L, INDS_R;
    for (int x: INDS) {
        if (b[x] + (ll) cnt * x > get_mn(x)) {
            INDS_L.emplace_back(x);
        } else {
            b[x] += (ll) cnt * x;
            INDS_R.emplace_back(x);
        }
    }
    INDS.clear();
    calc(l, MID, INDS_L);
    calc(MID + 1, r, INDS_R);
}

int ans[maxN];
mt19937 rnd(228);

void solve() {
//    srand(time(0));
    cin >> n >> q;
//    n = rnd() % 1000 + 1;
//    q = rnd() % 1000 + 1;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
//        a[i] = rnd() % 1000 + 1;
//        a[i] = inf;
//        cout << a[i] << " ??? " << endl;
    }
    for (int i = 1; i <= q; i++) {
        cin >> tp[i];
//        tp[i] = rnd() % 3 + 1;
        if (tp[i] == 1) {
            cin >> v[i];
//            v[i] = rnd() % 1000 + 1;
//            v[i] = 100000;
        } else if (tp[i] == 2) {
        } else if (tp[i] == 3) {
            cin >> l[i] >> r[i];
//            l[i] = rnd() % n + 1;
//            r[i] = rnd() % n + 1;
//            if (l[i] > r[i])
//                swap(l[i], r[i]);
        }
    }
    vector<int> INDS(n);
    iota(INDS.begin(), INDS.end(), 1);
    for (int i = 1; i <= n; i++) {
        b[i] = a[i];
    }
    for (int i = 1; i <= n; i++) {
        frst[i] = q + 1;
    }
    calc(1, q, INDS);


//    for (int i = 1; i <= n; i++) {
//        int my = q + 1;
//        ll CUR = a[i];
//        cout << CUR << " ???? " << frst[i] << " " << v[1] << " " << tp[1] << endl;
//        for (int j = 1; j <= q; j++) {
//            if (tp[j] == 2) {
//                CUR += i;
//            } else if (tp[j] == 1) {
//                if (CUR > v[j]) {
//                    my = j;
//                    break;
//                }
//            }
//        }
//        assert(my == frst[i]);
//    }

    PRE_SEG::build(1, 1, n);
    AFTER_SEG::build(1, 1, n);

    for (int i = 1; i <= n; i++)
        b[i] = a[i];

    for (int i = 1; i <= n; i++)
        g_frst[frst[i]].pb(i);

    for (int i = 1; i <= q; i++) {
        if (tp[i] == 1) {
            for (auto j: g_frst[i]) {
                PRE_SEG::upd(1, 1, n, j);
                AFTER_SEG::add(1, 1, n, j, v[i]);
                c[j] = 1;
                b[j] = v[i];
            }
            AFTER_SEG::upd(1, 1, n, v[i]);
//            cerr << n * v[i] << " " << AFTER_SEG::t1[1] << endl;
//            for (int j = 1; j <= n; j++)
//                b[j] = min(b[j], v[i]);
        }
        if (tp[i] == 2) {
            PRE_SEG::cnt++;
            AFTER_SEG::upd();

//            for (int j = 1; j <= n; j++)
//                b[j] += j;
        }
        if (tp[i] == 3) {
            ll res = 0;
            res += PRE_SEG::get(l[i], r[i]);
            res += AFTER_SEG::get(1, 1, n, l[i], r[i]);
//            ll tup = 0;
//            for (int j = l[i]; j <= r[i]; j++)
//                tup += b[j];
//            assert(tup == res);
            cout << res << "\n";
        }
    }

}

int main() {
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    int t = 1;
//    cin >> t;
    for (int i = 1; i <= t; i++) {
//        cout << "Case #" << i << endl;
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 40364kb

input:

13 11
6 14 14 6 3 6 4 13 10 3 12 5 11
1 2
2
2
2
1 11
3 4 6
2
1 6
2
1 9
3 2 13

output:

33
107

result:

ok 2 number(s): "33 107"

Test #2:

score: 0
Accepted
time: 8ms
memory: 40704kb

input:

5000 5000
29940 259997 53132 912489 608312 594283 432259 344137 889466 383028 320097 337418 571199 372832 563110 542407 133378 998389 238387 120880 477310 634888 191990 133585 935315 558139 141724 893331 190118 991968 843042 384930 935256 891482 123419 91431 955722 376987 197566 106433 234494 645967...

output:

512185934
455189773
121665669
408693244
291779262
45671866
242375008
302245547
222004631
41963113
343434445
347127029
183849524
2144625
278637672
220461451
20719635
108759503
22099550
34631220
55848925
92362584
36949030
86469096
43509864
50829332
1334865
76069109
114623436
13564322
79974466
15230088...

result:

ok 1671 numbers

Test #3:

score: 0
Accepted
time: 1ms
memory: 40556kb

input:

5000 5000
754848159362 799142221874 945332296572 929342054343 220343371940 207059247564 870301066785 609144766745 830351478389 198801101804 768950635554 592202774571 800496073014 730985048260 581401590014 934021096780 587980626010 77068543347 206074783770 390850923112 122794404396 281461236458 11092...

output:

116508179221533
546749128093796
194349368397972
39703523008217
175276724949769
115828286259777
53486037590699
32085609121169
79863137176116
53634397678952
11984901865039
53065256000101
29045072084569
26415198892331
75111789355520
75384800485844
34569350111656
133340053405484
51324651695791
973372919...

result:

ok 1647 numbers

Test #4:

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

input:

5000 5000
2572389899 2379766449 7410864819 2850299650 5617053831 3824312403 9814616879 8435146331 612453351 6111276232 7985477358 2776770282 2475123938 8017080204 7914003508 932800576 1394850160 1615934603 2716519725 6482033755 4787594046 7431658437 9394772703 5567857454 8294657000 2254310003 522061...

output:

10215584720705
1705389861
345800268
2011341781
2308552335
292528530
262542520
978988815
1435722498
941192965
986070818
873158540
1424652645
128856850
1383766618
1238322582
1869688874
820493117
1165528560
1332973518
2307494520
999182443
932104492
823277168
1062040845
1227853390
1624003330
1769087853
...

result:

ok 1677 numbers

Test #5:

score: 0
Accepted
time: 5ms
memory: 40664kb

input:

5000 5000
999809 999517 999488 999380 999248 998857 998620 998604 998567 998308 998186 997997 997810 997577 997322 997020 996746 996534 996197 995855 995826 995640 995600 995210 995081 994967 994685 994625 994443 994442 994262 993784 993725 993555 993306 993103 993081 992995 992414 991911 991909 991...

output:

16773634
412440775
172002115
859804112
771558481
736128415
379732036
26069114
230547108
124250573
144893959
16706694
204005800
25688354
45410890
426029778
358724432
507488261
286534500
26563180
474284154
22346892
56002662
236061693
295241526
137542524
22942480
293165763
323726733
160884504
192510432...

result:

ok 1650 numbers

Test #6:

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

input:

5000 5000
29989 29976 29976 29973 29966 29964 29960 29959 29950 29950 29943 29942 29939 29934 29931 29921 29914 29898 29873 29853 29845 29839 29833 29823 29793 29789 29779 29767 29765 29763 29759 29743 29742 29727 29724 29717 29711 29711 29710 29709 29709 29705 29695 29692 29687 29683 29678 29673 29...

output:

1677454
842408
7914094
20958765
1919270
1922628
25681578
7752212
4645740
4828824
44635274
4507503
10332327
943492
14007222
24519700
6369696
10888484
8301980
21731014
46268553
396
671
5698
12727
10692
121644
1954398
26911503
6554385
672220
8506939
3468479
3589800
9368964
17529036
9895900
4797296
6049...

result:

ok 1647 numbers

Test #7:

score: 0
Accepted
time: 2ms
memory: 40604kb

input:

5000 500
29995 29990 29989 29988 29985 29981 29976 29971 29964 29937 29930 29922 29919 29910 29883 29883 29866 29864 29855 29855 29850 29843 29842 29836 29834 29828 29827 29821 29820 29819 29819 29818 29817 29814 29800 29799 29798 29794 29783 29777 29769 29765 29758 29754 29750 29745 29741 29741 297...

output:

29842583
9940497
16817240
29922210
13110978
400953
90403379
2520804
5008146
8960380
3019016
10404797
2657305
48660920
16149760
15343500
41648193
29264570
13432320
11089916
14534100
24971099
6748971
9015984
10408641
16352180
4234968
14245138
15540872
8479523
1054657
11951303
1314467
20398020
3903982
...

result:

ok 159 numbers

Test #8:

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

input:

500 5000
29998 29894 29881 29844 29816 29792 29788 29741 29403 29329 29188 29184 29044 29039 28923 28878 28667 28624 28578 28567 28397 28374 28266 28233 28185 28120 28078 27835 27806 27778 27770 27769 27501 27475 27387 27320 27318 27209 27188 27183 27173 27125 27005 26977 26972 26949 26927 26784 267...

output:

101428
529856
311680
1060052
1284458
1226856
517734
141825
690886
1436243
203775
8910
110817
371700
196416
294690
543780
541581
126474
545259
91364
399750
635400
380254
32571
989562
786370
25752
67921
22420
99330
155855
69388
338997
150689
187210
550625
194129
23481
662186
343232
75411
225330
155133...

result:

ok 1622 numbers

Test #9:

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

input:

200000 200000
230887273973 981603875652 113292402721 438678940199 836631032882 266043112082 527547838654 732594084126 329246064377 369715767534 658438750450 410647482510 267084058934 877638442790 42545402543 840640973131 524426029052 933194442797 563955124048 700439032209 703056463665 314702014994 2...

output:

57598679467633984
27633342974043229
53103855900352089
23674346835506590
3852674985707986
10275950481054823
12431303365285554
8544611655980608
2389235296573674
14032171746842112
1989852345437218
3023474254710557
10206172732678237
566682480788486
12841355927078228
3314140857532774
6853056879869055
426...

result:

ok 66471 numbers

Test #10:

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

input:

200000 200000
193280545702 655617907032 520020568122 924552667378 143594139030 973986202692 536112328511 593191407420 600294405318 537716863876 647369589347 474895911916 561323875673 502611350541 439667606274 729797591406 918513719062 639756485309 395779313629 313489354572 465191320917 553170969320 ...

output:

608863633738238
3786927180142094
452103531234633
9664234826140346
29026059002382136
24626742579548575
8886732675995524
779910843983231
2664698300317277
6258050515383222
17217896068263017
5082078116244856
10914646545075317
25332887896820678
17674862074825538
1017547586322428
4733495089038952
11748392...

result:

ok 66828 numbers

Test #11:

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

input:

200000 200000
519459450162 10879845041 930700340890 892959388241 854791814543 697685193883 214253752600 273258877854 55159208956 892528231362 389836726316 703506482099 8610606141 85845790634 548326805992 836725246847 24092217406 514192553898 762371990803 647463229778 56673708852 261110727557 5879224...

output:

39205765295178795
19123794695653611
6688678461324366
369254584590641
12204684998168247
2332887959581270
6683195406547104
1449824999639067
265480482360672
5217805914373175
503972221924653
5579714074875033
1132395782107834
1844018899364696
3013742383536550
1060251548537743
238726901964514
458326212186...

result:

ok 99706 numbers

Test #12:

score: 0
Accepted
time: 398ms
memory: 87224kb

input:

200000 200000
901619236607 229030223535 679386583228 190374644028 58031782631 737434362236 974717299120 326289231381 850178711788 572269302384 395499531010 850383556703 579279902202 668752975933 728660086625 857293773198 445790473881 565179337801 280677040114 32224664946 562818265582 181541361344 61...

output:

1275442438330896
8838001159737540
50499694707535958
20165817812874840
64655040338209555
5433453815868744
4414909789423188
38306143042800529
55623475031738851
29689330077939129
7296551101395907
24128395443163258
3048915450254147
5133008146105073
15631430569981527
66523135762209041
22470109680084636
1...

result:

ok 100024 numbers

Test #13:

score: 0
Accepted
time: 405ms
memory: 87144kb

input:

200000 200000
151175092976 480733920796 954541843791 37071389761 240832283311 404155609129 131019514221 723671407122 165960566854 225889751534 234448055587 201019492277 962247070725 162544894688 770426645620 164597430494 44291808374 254915970799 674679047898 364129225162 681492855983 726305138512 31...

output:

12808771883852719
39081325086944602
12200963694213489
19495036267486838
24924410701212543
3404713078393901
60829263182665086
9093081487569193
59801317472987717
19451520100885672
76033338993776314
36291046109532215
16662831887581399
16790991960577253
29347278110822521
28572850815383369
21603619626072...

result:

ok 100219 numbers

Test #14:

score: 0
Accepted
time: 384ms
memory: 87328kb

input:

200000 200000
95927737926 487725336029 705349249237 997726652866 173360072684 568671847607 172340813662 220315350673 890604552228 921278233676 968767777674 255765699217 978663811808 462862864660 645440541041 952407850722 929885843202 316927306610 404428282059 322253458271 860533867124 517983912159 2...

output:

21704154848595534
13158194964479881
73466940316068200
17818601840905782
10166446947806264
18548801265958056
35076654271775052
43257916928169525
15604382483486076
26736898942897660
9681213159141721
23268440273561822
33849693911864754
47128037671790681
35218603239709065
50563303253216912
5083632650864...

result:

ok 100247 numbers

Test #15:

score: 0
Accepted
time: 308ms
memory: 86732kb

input:

200000 200000
191252 227429 491475 556365 786769 926329 948870 1043650 1093196 1139909 1277202 1279757 1334515 1336136 1390278 1484390 1524885 1537601 1583562 1782357 1841993 1860169 1980233 2055130 2133890 2330094 2385978 2428755 2472643 2526678 2618269 2683541 2792468 2797609 3064717 3293613 33851...

output:

42076242240948
231798130644482
247788126509035
59214835347535
73309970001345
86524461459117
221889711221502
400759035253967
84292125610560
254501146580087
29341327969725
104005851653754
84787007731965
320909856874297
45955730955577
76244793603984
62835433655124
73454942229569
50095708867455
25241327...

result:

ok 66636 numbers

Test #16:

score: 0
Accepted
time: 294ms
memory: 86600kb

input:

200000 200000
6442426554 2147397484 10737321272 2147383558 15032285334 15032255739 2147309981 6442234238 19327126127 6442212022 19327078104 19327062270 15032087160 15032080134 10737104616 10737084127 19327004522 2147124658 2147096333 10737025355 6442054368 6442046373 2147076846 2147044443 1503193849...

output:

39833988772662
209351651095865
224174842512704
51611872629251
67398262057746
73736846619010
201518991348651
385005808110660
70421461374900
240375540493550
29341327969725
104005851653754
84787007731965
303818735694424
42647981586703
68768462988647
52645368736491
73454942229569
43546088304187
23664453...

result:

ok 66636 numbers

Test #17:

score: 0
Accepted
time: 313ms
memory: 89100kb

input:

200000 200000
15901713831 6233809633 19393974811 1189791030 18541044905 8430067003 556407857 15850921865 11031755810 11209458447 16304654166 7966143869 11502772528 18902330000 6433415717 13726335624 4108400396 12690579967 4278674893 16478187674 3425380315 10483121227 1292045692 655144602 19579077688...

output:

143775232361866
193657547430713
228515508694218
204765162536474
68087468429223
102717476357429
147277077953476
231345399231541
51118170955676
100779007121400
236997353116176
240121295523856
77231031103739
184028479204213
148604068825485
220675627480995
255992107105434
60553469216082
43399144056865
2...

result:

ok 66727 numbers

Test #18:

score: 0
Accepted
time: 200ms
memory: 86688kb

input:

200000 200000
1993 149973 278092 318002 362096 573666 607328 616959 644323 690466 730411 798782 810762 812315 997370 1237948 1333119 1351804 1368126 1407879 1428867 1481850 1500879 1537250 1762605 1763551 2203081 2435764 2525891 2686307 2708274 2798329 2885489 2941237 3230203 3312917 3409133 3484356...

output:

304124817774874
409703458489468
452923942039293
433170144646087
143936457735447
217155826291572
311452626178304
440300192383366
47665819372630
180372442633376
484974122281284
507638035417553
163175285824306
388997446533540
252586337256032
466538709019648
483829188041696
128055229086249
9170783554182...

result:

ok 66727 numbers

Test #19:

score: 0
Accepted
time: 224ms
memory: 86408kb

input:

200000 200000
6442441065 15032340849 19327271761 19327226953 15032220785 19327168998 6442242323 10737206178 6442167460 10737048551 10737029624 2147044445 6442007755 15031917113 15031902018 15031873496 19326826059 10736880469 10736806375 15031746100 6441753345 19326648437 15031674847 10736660564 2146...

output:

265472195691612
362913117494445
419427401049356
385537186942723
132060290300826
198830027774482
283183152064356
422684648971083
95319200632696
183529715882176
438757034804847
456134692173252
149434493588996
352450023202775
269807910250985
411657514290129
472083229487006
121485079055260
8390820205980...

result:

ok 66727 numbers

Test #20:

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

input:

200000 200000
393299030 2413210430 19590781075 16648079580 10108963066 9882562807 1901415169 1765079131 6839871040 10228747503 14456713948 10736615674 3112713601 10413710512 13485660358 14439074981 18895050622 12765606763 11845120741 761151573 7531835856 1600452417 6333574018 15432009075 18414674875...

output:

136234601951362
200265939601106
529992729687584
341587050709208
770146286715608
607844345885276
10997907141851
377573069005832
142528387412438
193912229779017
59511896571584
294812438548104
65442300494867
192160603257736
455070400835055
528132376597701
282210269044327
599242312851595
154648162174497...

result:

ok 66830 numbers

Test #21:

score: 0
Accepted
time: 231ms
memory: 86732kb

input:

200000 200000
19245 111079 278732 308208 376171 453261 494883 604312 637754 732638 788344 936908 1063044 1122726 1328454 1424417 1486844 1779768 2235799 2461471 2551563 2569564 2685715 2743302 2899789 2932361 3193115 3233480 3293131 3306314 3379902 3443692 3546228 3639661 3695154 3700215 3700240 373...

output:

491076841217339
486897889142271
540097650834494
408009279261520
67422841488784
46796013085085
301093866782395
218419249260032
444378488933688
520774140806086
263725937037555
101472599334939
240850747928674
261173503592094
267576730002240
123382661594918
483924249213227
549772563371767
16445307568115...

result:

ok 66830 numbers

Test #22:

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

input:

200000 200000
19327350750 19327340202 19327331767 15032363149 15032299867 10737282787 6442286498 19327172610 10737224087 2147278109 2147274486 6442236528 2147234718 19327083242 15032113075 2147210049 19327076945 19327060718 15032088669 15032072125 2147161943 6442122628 6442117090 2147146805 21471156...

output:

249593258471123
53462379827313
127982812908377
198215155992368
136670157163291
80605101703104
325608348792183
8636851847990
23275990295395
110260784637837
169496982946170
396110435076024
230394593552920
665135212429957
43743881504410
162973021784703
471675440430814
401955596523328
245432869753505
40...

result:

ok 66723 numbers

Test #23:

score: 0
Accepted
time: 264ms
memory: 89340kb

input:

200000 200000
16929011942 799398795 2514431551 5781703871 12451140818 15176502049 390606647 849080666 11529839445 75684023 16404045836 2924527899 15066442272 17949052078 2157936752 12653859244 9836248970 12320376408 5058702897 5344997737 10185217384 17396241449 15319591898 11212170183 9675336620 496...

output:

234849874498791
51100317350792
118751080489275
202211611222720
127613089370275
85376273907624
328565750682125
7840814625075
23523810074345
120412032860055
163871054362695
382929269837276
218228554792009
667036690616000
40127771717240
176102577781363
476131505301683
396429901996398
231638236211993
38...

result:

ok 66723 numbers

Test #24:

score: 0
Accepted
time: 199ms
memory: 86472kb

input:

200000 200000
99999930 99999091 99998867 99998447 99997598 99996501 99996166 99995222 99995063 99994995 99994744 99994369 99994288 99994110 99993862 99993653 99993108 99993091 99992295 99992284 99992258 99992050 99991417 99991386 99991241 99991074 99990623 99989588 99988164 99987818 99987783 9998774...

output:

532544673773
1500817047189
1382229387000
1074493227690
20717002756
109053696969
193645293945
1561097718687
453224709725
296116979265
549586630632
471210705104
756772090932
685225462894
69687538317
337220075151
281990916648
161042417664
305914822729
123418840160
408491745970
682597811571
51766819320
...

result:

ok 66495 numbers

Test #25:

score: 0
Accepted
time: 236ms
memory: 85956kb

input:

200000 200000
9999917 9999892 9999839 9999805 9999793 9999782 9999769 9999699 9999673 9999597 9999554 9999429 9999345 9999283 9999210 9999190 9999142 9999134 9998927 9998885 9998876 9998857 9998801 9998777 9998761 9998676 9998603 9998365 9998239 9998226 9998217 9998191 9998163 9998114 9998084 999797...

output:

128910867018
698029668823
50254373968
259501142505
379202077337
212195471410
474363154334
71341995019
280905843025
101398151302
8603103448
82116979593
62365927311
300012728790
308182713000
46959308418
9666066438
188342121840
39249040050
147258900360
215152408632
96324525659
63392330187
220992376788
...

result:

ok 66558 numbers

Test #26:

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

input:

200000 200000
1000000 1000000 999999 999996 999990 999987 999984 999973 999963 999957 999951 999951 999950 999950 999942 999942 999942 999937 999906 999906 999902 999899 999896 999894 999894 999889 999873 999870 999870 999870 999865 999862 999861 999854 999844 999843 999838 999837 999832 999831 9998...

output:

10834309761
6405768249
422537591
17416690812
7441066010
6640546175
17520865791
1810035760
1056067929
11025406327
288545075
45134681643
610472093
35549739030
28456888837
5485912124
38829936644
2878456698
41221459
7346029617
52302313909
18904668075
8613772029
5318475054
14225875848
11923331070
1963112...

result:

ok 66548 numbers

Test #27:

score: 0
Accepted
time: 233ms
memory: 86272kb

input:

200000 200000
42566 72749 58134 38791 6387 74273 18997 90680 49795 74669 36808 71291 13087 62582 51344 99660 38155 55867 81585 10412 82437 55498 3718 36698 13850 8946 19408 89752 16404 83451 91253 10716 86699 51892 62085 49025 99780 69506 56590 70715 33725 4424 80883 9372 42330 10517 97691 90291 647...

output:

6095615825
1255555212
1656728824
4627196151
1499978445
442424576
5257358722
3958746534
37924810930
12662869990
20520978304
117153959653
96527195491
10566895895
2645363818
97975664112
77523190024
236643245473
100982467972
312381387942
14126594274
60389773854
111778214140
307704057712
133240459736
109...

result:

ok 66488 numbers

Test #28:

score: 0
Accepted
time: 197ms
memory: 86780kb

input:

200000 200000
663572405461 36507118070 526133361097 895500521651 221190622823 856845775083 603442700408 70866720301 49391860323 113816351347 839665819071 994284611391 251255263887 564787874544 989989632186 36506800741 624917318529 663572006553 556197824071 70866513843 70866474218 384399026919 818190...

output:

6288469295135498
48044182926579564
262688455411195
10129701232343862
5059937489547371
6036904094354187
24217376407814383
305146206408679
119285377661915
90363586450587
500129586221951
195151836181463
124800302239542
47277228326568
97964884311632
57488836747901
462388690922028
148401459183957
5276343...

result:

ok 66769 numbers

Test #29:

score: 0
Accepted
time: 225ms
memory: 86532kb

input:

200000 200000
27917273102 36507189839 19327317011 70866921858 79456827230 32212185029 88046729062 53686982047 62276916503 83751744589 92341665852 6442314470 92341652106 57981908602 10737213255 79456677422 83751635770 32211995470 10737157231 79456612237 79456574787 70866634621 96636419133 2147114828 ...

output:

791607924002531
6398552422568555
2654525985455328
4103354323172853
2181868288286338
3739811572926904
1006153809963999
1032925413593849
3359519076911345
962540940306388
357237915740751
1776015586340503
34827181371249
1561359958091111
200540209510549
273523679042331
225438357425135
328843841388347
657...

result:

ok 66621 numbers

Test #30:

score: 0
Accepted
time: 237ms
memory: 86500kb

input:

200000 200000
6442414131 2147395917 6442348395 6442233383 6442184790 6442170567 2147155620 6442097244 6442081361 6442070810 6442064420 2147081029 6442034766 6441973142 6441966457 6441956706 2146968154 2146945458 6441907865 2146932173 6441894712 6441852836 2146879901 6441839051 2146859777 2146859174 ...

output:

410385448335093
113880117144107
53064973579572
178666040001376
191109859971295
17139113087155
38700994452231
24199688029563
55880376893263
42388829985841
4811813212240
8908792880086
40811213097611
24978547044288
21462247144140
10786120445806
25862419886665
55083808424723
35602584171909
3488463712973...

result:

ok 66929 numbers

Test #31:

score: 0
Accepted
time: 222ms
memory: 86220kb

input:

200000 200000
999998109 999996005 999993823 999986509 999981378 999963732 999963613 999962876 999961274 999954235 999949943 999947614 999946064 999942597 999941622 999938047 999937306 999934905 999930598 999924026 999917726 999915453 999914766 999907497 999894539 999893438 999891947 999886407 999881...

output:

10942156666052
4783520521078
1827233955365
5352679368605
740791692540
3991560558201
2164981072742
520201011526
858872056372
2220911895370
3297162849323
5091519895240
1083735827185
358335595979
6923997554725
3209530900080
5163050493629
1048954042994
3476270216556
607153346334
1811831532489
2828579859...

result:

ok 66899 numbers