QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#946103#10183. 멋진 구간cooluo100 ✓534ms131404kbC++236.9kb2025-03-21 16:22:532025-03-21 16:22:54

Judging History

This is the latest submission verdict.

  • [2025-03-21 16:22:54]
  • Judged
  • Verdict: 100
  • Time: 534ms
  • Memory: 131404kb
  • [2025-03-21 16:22:53]
  • Submitted

answer

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

#define ll long long
#define ul unsigned ll
#define LL __int128_t
#define db double
#define DB long db
#define pii pair<int, int>
#define fi first
#define se second
#define mkpr make_pair
#define vi vector<int>
#define vii vector<pii>
#define rsz resize
#define ep emplace
#define pb pop_back
#define eb emplace_back
#define all(c) (c).begin(), (c).end()
#define bit(k) (1 << (k))
#define Bit(k) (1ll << (k))
#define BIT(k) ((LL)1 << (k))
#define lowbit(x) ((x) & -(x))
#define bin(s, k) ((s) >> (k) & 1)
#define lg2(x) (31 - __builtin_clz(x))
#define LG2(x) (63 - __builtin_clzll(x))
#define highbit(x) bit(lg2(x))
#define highbitll(x) Bit(LG2(x))
#define popcnt(x) __builtin_popcount(x)
#define mem(a, x) memset(a, x, sizeof(a))
#define req(i, l, r) for (int i(l), i##End(r); i < i##End; i = -~i)
#define rep(i, l, r) for (int i(l), i##End(r); i <= i##End; i = -~i)
#define per(i, r, l) for (int i(r), i##End(l); i >= i##End; i = ~-i)

// #define FILERR

#ifdef JYR
#include "debug.h"
#define errm(x, ...) fprintf(stderr, x, ##__VA_ARGS__)
#define errs(x, ...) errm(x "\n", ##__VA_ARGS__)
#else
#define dbg(...) (__VA_ARGS__)
#define dbgArr(...) (__VA_ARGS__)
#define errm(x, ...) (x, ##__VA_ARGS__)
#define errs(x, ...) (x, ##__VA_ARGS__)
#endif

#define __

template<typename T, typename U> void chkmx(T &_a, U _b) { if (_a < _b) _a = _b; }
template<typename T, typename U> void chkmn(T &_a, U _b) { if (_b < _a) _a = _b; }

#define vll vector<ll>

// #define MC

#define N 250005
#define mod 998244353
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f

struct Info {
    ll mx, ml, mr, su;
    Info() {}
    Info(ll x) { mx = ml = mr = su = x; }
    Info(ll _mx, ll _ml, ll _mr, ll _su)
     : mx(_mx), ml(_ml), mr(_mr), su(_su) {}
};

Info operator+(Info a, Info b) {
    return Info(max({a.mx, b.mx, a.mr + b.ml}),
                max(a.ml, a.su + b.ml),
                max(a.mr + b.su, b.mr),
                a.su + b.su);
}

int n, q;
ll a[N], b[N];
ll A[N], B[N];
pii L[N], R[N];
int st[N], tp;
int f[N], g[N];
ll mx[21][N];
struct node {
    int o, l, r, x, i;
    node() {}
    node(int _o, int _l, int _r, int _x, int _i = 0)
     : o(_o), l(_l), r(_r), x(_x), i(_i) {}
}; vector<node> V;
ll ans[N];

struct SegTree {
    #define lc (i << 1)
    #define rc (lc | 1)
    
    Info vl[N << 2];
    
    void psu(int i) { vl[i] = vl[lc] + vl[rc]; }
    
    void bld(int i = 1, int l = 1, int r = n) {
        if (l == r) { vl[i] = Info(a[l]); return; }
        int t = (l + r) >> 1; bld(lc, l, t), bld(rc, t + 1, r);
        return psu(i);
    }
    
    Info qry(int u, int v, int i = 1, int l = 1, int r = n) {
        if (u <= l && r <= v) return vl[i];
        int t = (l + r) >> 1;
        if (v <= t) return qry(u, v, lc, l, t);
        if (t < u) return qry(u, v, rc, t + 1, r);
        return qry(u, v, lc, l, t) + qry(u, v, rc, t + 1, r);
    }
} T;

struct STree {
    ll su[N << 2], ct[N << 2], tg[N << 2];
    
    void psu(int i) { su[i] = su[lc] + su[rc], ct[i] = ct[lc] + ct[rc]; }
    void chg(int i, ll k) { su[i] += ct[i] * k, tg[i] += k; }
    void psd(int i) { if (ll &k = tg[i]; k) chg(lc, k), chg(rc, k), k = 0; }
    
    void mdf(int u, int v, int k, int i = 1, int l = 1, int r = n) {
        if (u <= l && r <= v) return chg(i, k);
        int t = (l + r) >> 1; psd(i);
        if (u <= t) mdf(u, v, k, lc, l, t);
        if (t < v) mdf(u, v, k, rc, t + 1, r);
        return psu(i);
    }
    
    void mdg(int p, int k, int i = 1, int l = 1, int r = n) {
        if (l == r) { ct[i] += k; return; }
        int t = (l + r) >> 1; psd(i);
        p <= t ? mdg(p, k, lc, l, t) : mdg(p, k, rc, t + 1, r);
        return psu(i);
    }
    
    ll qry(int u, int v, int i = 1, int l = 1, int r = n) {
        if (u <= l && r <= v) return su[i];
        int t = (l + r) >> 1; psd(i); ll res = 0;
        if (u <= t) res += qry(u, v, lc, l, t);
        if (t < v) res += qry(u, v, rc, t + 1, r);
        return res;
    }
} S;

ll qry(int l, int r) {
    int k = lg2(r - l + 1);
    return max(mx[k][l], mx[k][r - bit(k) + 1]);
}

vll maxsum(vi _a, vi _b, vi _l1, vi _r1, vi _l2, vi _r2) {
    // rd(n, q);
    // rep(i, 1, n) rd(a[i], b[i]);
    n = _a.size(), q = _l1.size();
    rep(i, 1, n) a[i] = _a[i - 1], b[i] = _b[i - 1];
    rep(i, 1, n) A[i] = A[i - 1] + a[i];
    rep(i, 1, n) B[i] = B[i - 1] + b[i];
    ll t = 0;
    rep(i, 2, n) {
        if (A[i - 1] - t > 0) L[i].fi = -1;
        chkmn(t, A[i - 1]);
    }
    t = A[n];
    per(i, n - 1, 1) {
        if (t - A[i] > 0) R[i].fi = -1;
        chkmx(t, A[i]);
    }
    st[tp = 0] = n + 1;
    per(i, n, 0) {
        while (tp && B[st[tp]] >= B[i]) tp--;
        f[i + 1] = st[tp] - 1, st[++tp] = i;
    }
    reverse(B, B + n + 1), st[tp = 0] = n + 1;
    per(i, n, 0) {
        while (tp && B[st[tp]] <= B[i]) tp--;
        g[i + 1] = st[tp] - 1, st[++tp] = i;
    } reverse(B, B + n + 1), reverse(g + 1, g + n + 1);
    rep(i, 1, n) g[i] = n + 1 - g[i];
    rep(i, 1, n) if (~L[i].fi) L[i].se = max(f[i], i);
    rep(i, 1, n) if (~R[i].fi) R[i].fi = min(g[i], i);
    rep(i, 1, n) mx[0][i] = B[i];
    rep(k, 1, 20) rep(i, 1, n - bit(k) + 1)
        mx[k][i] = max(mx[k - 1][i], mx[k - 1][i + bit(k - 1)]);
    T.bld();
    rep(i, 1, n) if (~L[i].fi) {
        ll X = i == 1 ? -INF : T.qry(1, i - 1).mx;
        int l = i, r = n, k = n + 1;
        while (l <= r) {
            int x = (l + r) >> 1;
            qry(i, x) - B[i - 1] >= X ? k = x, r = x - 1 : l = x + 1;
        } L[i].fi = k;
    }
    rep(i, 1, n) mx[0][i] = -B[i - 1];
    rep(k, 1, 20) rep(i, 1, n - bit(k) + 1)
    mx[k][i] = max(mx[k - 1][i], mx[k - 1][i + bit(k - 1)]);
    rep(i, 1, n) if (~R[i].fi) {
        ll X = i == n ? -INF : T.qry(i + 1, n).mx;
        int l = 1, r = i, k = 0;
        while (l <= r) {
            int x = (l + r) >> 1;
            B[i] + qry(x, i) >= X ? k = x, l = x + 1 : r = x - 1;
        } R[i].se = k;
    }
    rep(i, 1, n) if (~L[i].fi && L[i].fi <= L[i].se) V.eb(0, i, i, L[i].fi), V.eb(4, i, i, L[i].se);
    rep(i, 1, n) if (~R[i].fi && R[i].fi <= R[i].se) V.eb(1, R[i].fi, R[i].se, i);
    rep(i, 1, q) {
        int l, r, u, v;
        // rd(l, r, u, v);
        l = _l1[i - 1], r = _r1[i - 1], u = _l2[i - 1], v = _r2[i - 1];
        l++, r++, u++, v++;
        V.eb(2, l, r, u - 1, i), V.eb(3, l, r, v, i);
    }
    sort(all(V), [](node i, node j) { return mkpr(i.x, i.o) < mkpr(j.x, j.o); });
    for (auto [o, l, r, x, i] : V) switch (o) {
        case 0: S.mdg(l, 1); break;
        case 1: S.mdf(l, r, 1); break;
        case 2: ans[i] -= S.qry(l, r); break;
        case 3: ans[i] += S.qry(l, r); break;
        default: S.mdg(l, -1);
    }
    // rep(i, 1, q) prs(ans[i]);
    vll _ans;
    rep(i, 1, q) _ans.eb(ans[i]);
    return _ans;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 5
Accepted

Test #1:

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

input:

1 1
-1000000000 -1000000000
0 0 0 0

output:

1

result:

ok single line: '1'

Test #2:

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

input:

1 1
1000000000 1000000000
0 0 0 0

output:

1

result:

ok single line: '1'

Test #3:

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

input:

1 1
-1000000000 1000000000
0 0 0 0

output:

1

result:

ok single line: '1'

Test #4:

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

input:

3 3
-1 2
-1 -1
-1 2
0 2 0 2
0 0 0 2
1 2 0 1

output:

4 2 1

result:

ok single line: '4 2 1'

Test #5:

score: 5
Accepted
time: 141ms
memory: 58372kb

input:

500 250000
-558628852 866881264
-830698849 416046552
363194605 615243557
63030656 765290363
-555104669 209257664
-447105150 -413543083
-919444090 -490557087
645491722 788852656
-474842431 581716236
-470342920 991054910
-523742949 233654838
41273442 186150587
-953805233 -676930931
-712428675 -2251144...

output:

9368 127 1551 0 931 11305 0 837 8470 0 0 7566 2077 4740 9704 6503 460 7594 2834 536 8064 11 2535 60 13696 0 0 874 1420 0 0 400 5793 4559 1606 3780 78 4051 2533 3237 2532 4035 3862 2 1556 0 3464 271 1729 8625 658 2 0 3192 312 4994 3472 720 0 1889 265 0 861 972 0 448 60 28 1900 364 2850 4420 332 12177...

result:

ok single line: '9368 127 1551 0 931 11305 0 83... 3404 960 561 0 3494 2686 153 0'

Test #6:

score: 5
Accepted
time: 141ms
memory: 60384kb

input:

500 250000
-777684370 619041451
-857347367 -513538963
-698112035 694152582
-150950961 -98941503
-292017554 743843635
-677334505 824359299
-237154170 698373924
-271230205 637783977
-723796028 -480349609
-990861128 888130227
-983301921 -437102379
-105312382 589583130
-165579679 730413927
-11228476 280...

output:

0 4287 2090 674 3765 2600 0 262 474 0 106 1584 888 189 1236 2050 0 0 2728 170 1217 4885 228 5472 6721 2595 2650 0 5649 817 1037 12 4715 0 4231 4591 38 12850 144 1 2286 0 990 78 10226 917 5738 0 12552 878 424 2357 990 3749 92 6277 6151 4914 0 1710 0 17121 0 3596 4754 4215 10464 716 3711 598 1656 355 ...

result:

ok single line: '0 4287 2090 674 3765 2600 0 26...435 8987 2010 410 2282 2114 480'

Test #7:

score: 5
Accepted
time: 141ms
memory: 60428kb

input:

500 250000
-454886332 475386580
-116802309 708811186
-329081047 194451321
-916597965 828385245
-619141551 786618797
-975808727 833026578
-214281542 624305688
-624631429 239229038
-643233597 239213929
-615618965 872309582
-288403791 525369552
-803099041 765807063
-872834261 378510978
-958459295 21440...

output:

0 981 1938 4508 9936 0 3227 7857 6475 48373 6142 9057 7814 0 0 1377 2296 6954 589 4500 0 38651 4872 1616 67 20300 11049 0 27841 11099 0 1718 11675 0 26673 0 1800 2057 1849 3047 0 29390 337 4078 0 0 50031 34704 2515 13617 2121 12602 6122 491 3163 750 77147 18060 9552 0 2730 64 10052 0 92897 0 18591 1...

result:

ok single line: '0 981 1938 4508 9936 0 3227 78... 3178 0 51101 5142 712 4284 0 0'

Test #8:

score: 5
Accepted
time: 146ms
memory: 58380kb

input:

500 250000
-276802908 198678528
-523021755 439473368
-349731794 179121586
-186825981 466536529
-398207395 68922979
-301548287 889553618
-571448748 503907930
-402661106 316676955
-214761682 538685679
-447220947 311573823
-996115850 145517330
-287991532 282648742
-850520404 248821187
-245365074 601864...

output:

47356 35440 18645 4290 0 0 38434 6789 5350 19604 0 17627 16899 26437 6884 32486 19433 54044 14804 17556 260 0 9319 33327 30099 748 0 1299 35525 19216 7211 3104 15741 16113 68620 0 505 35977 0 64 2934 93780 26913 0 19777 21558 48005 0 11735 5628 159 32585 53537 46 10386 24527 58162 536 10217 11454 0 ...

result:

ok single line: '47356 35440 18645 4290 0 0 384... 69 70711 14934 8717 9430 19291'

Test #9:

score: 5
Accepted
time: 140ms
memory: 62444kb

input:

500 250000
-393686780 772227373
-784017009 465102846
-515606732 723600363
-311829806 514753221
-472240536 351227161
-627287847 651113362
-633648658 528734363
-35466591 394124872
-931513960 397965942
-573790225 455870768
-849052102 60632404
-213075511 649747317
-123173843 824164099
-237303557 3275140...

output:

6425 70106 11285 34204 18818 7125 1969 16158 0 4400 22446 0 41362 11455 1140 13778 21765 1446 4225 4230 15787 827 18258 35530 0 144 42236 77212 13038 11358 3118 69706 28025 3740 114485 216 22869 535 4278 2099 68430 1934 0 0 10339 23844 26702 9743 9718 12031 8607 5659 19202 16479 48684 40230 12576 0 ...

result:

ok single line: '6425 70106 11285 34204 18818 7... 48101 18080 4177 41749 0 84140'

Test #10:

score: 5
Accepted
time: 135ms
memory: 60424kb

input:

500 250000
-529800412 -208199761
-630843500 17710290
-629646518 292693279
-350906541 704941100
-556750201 -524898899
-267818137 149781615
-65322024 172571739
-853737927 930128154
-990786379 -857136339
-142742286 453068575
-357781147 -503844
-426459918 554426969
-622985055 979381914
-676895599 -42246...

output:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 713 0 0 0 0 0 0 0 0 112 0 0 0 0 510 0 0 0 0 0 0 0 22 56 0 247 0 0 0 0 0 0 208 1120 0 0 0 0 0 0 0 0 0 0 0 810 0 0 0 0 0 0 0 0 288 0 0 144 1360 0 0 0 795 0 0 0 0 0 0 0 0 720 0 663 0 0 0 0 0 0 0 0 360 486 0 0 0 1160 0 0 0 0 0 494 0 0 0 0 784 0 2024 0 0 0 0 0 432 0 0 0 0 0 ...

result:

ok single line: '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0'

Test #11:

score: 5
Accepted
time: 137ms
memory: 56296kb

input:

500 250000
-956251568 -114134710
-796718438 -506623940
-991495234 -282691263
-381678805 -7244992
-531923768 362884047
-984570415 113172321
-626057783 328263713
-338630418 361935628
-120476171 272317862
-119027974 687517170
-888270877 392795385
-310625105 -69054723
-498754980 709869789
-215422603 -34...

output:

0 0 0 0 0 0 403 0 0 0 744 0 672 0 0 0 0 0 0 0 72 0 0 0 0 0 208 0 0 216 0 0 0 527 0 0 6 0 0 0 0 0 0 0 0 0 576 0 0 0 0 0 0 0 0 0 384 0 0 0 0 0 0 0 0 0 0 0 0 155 0 0 0 0 0 0 0 0 0 0 0 713 0 0 0 0 0 0 420 0 490 0 0 0 0 0 0 1050 0 0 0 408 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 792 0 0 0 0 0 0 0 0 ...

result:

ok single line: '0 0 0 0 0 0 403 0 0 0 744 0 67...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5'

Test #12:

score: 5
Accepted
time: 138ms
memory: 56328kb

input:

500 250000
275827635 816352439
674851191 848791823
789883560 937216371
119044671 539899049
971609388 981897018
800207059 834021531
474390199 748765898
432813428 601125413
281738482 860979864
71338967 909989315
522074685 583617470
619423653 932481235
230107178 686797730
744147705 932878931
972262400 ...

output:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok single line: '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0'

Subtask #2:

score: 11
Accepted

Test #13:

score: 11
Accepted
time: 179ms
memory: 67096kb

input:

5000 250000
-350312323 690521627
-184990432 -8207971
-833021024 568813868
178555698 498352626
348389823 845924808
470117673 857091723
-616796209 954779515
-238971504 668994922
-63798913 537632636
-946014511 355777299
71556323 338229556
263320054 657791785
-843884375 592044407
338388911 858273134
-39...

output:

30151 0 382292 0 431236 132641 35748 529388 1351 0 4095 4953 1296289 507839 0 299 4043 38206 11845 300005 28255 52032 252837 594605 35596 0 590490 55783 29771 2030 0 198183 140935 282820 17094 143338 188247 21204 131937 0 724606 297561 80885 60715 53547 206753 670422 169481 270505 454143 71536 20899...

result:

ok single line: '30151 0 382292 0 431236 132641...1 0 669172 827726 400121 462468'

Test #14:

score: 11
Accepted
time: 179ms
memory: 67136kb

input:

5000 250000
-954044008 -877674727
-986634596 184046956
-797030341 960490983
-70911946 -35425920
-890988079 882975793
94994104 534855613
-363393292 815687320
700945636 904376969
236801538 631045451
-823806640 777102159
401286686 826305505
661296110 811629741
545367491 808428366
-717321099 -341058028
...

output:

51058 456579 26340 136770 172853 356286 105125 542461 156877 45210 7526 162478 80384 524892 64203 21267 60466 1170 0 9354 653397 140200 90492 279687 37150 177776 0 621326 148512 3588 21974 673145 866268 54990 0 1 11061 0 489472 195634 0 47194 699664 0 270613 222228 290544 788774 122562 240743 724079...

result:

ok single line: '51058 456579 26340 136770 1728...88 15477 311014 660156 0 716183'

Test #15:

score: 11
Accepted
time: 183ms
memory: 66984kb

input:

5000 250000
-551462909 619322244
-58570765 341318281
-101072367 335195083
-86114305 177506152
-812044698 199951246
-883795175 56341823
-120586886 771022163
-511318756 798340035
-911933783 311724323
-771687674 208968816
-364545868 207640844
-661360775 66238213
-745614785 428287389
-976452805 28630733...

output:

3299010 8462090 1939365 2665828 848808 10460307 30471 332513 187229 5069132 2181029 79797 0 0 0 4726248 0 1123556 4650450 8557262 0 2898208 591519 2035401 758436 150518 52647 1292692 3813451 47583 0 4756112 304583 930702 1117077 2157331 2085886 0 24403 0 214060 9509075 0 359133 441323 1013162 44884 ...

result:

ok single line: '3299010 8462090 1939365 266582...172 5102701 0 779 724590 798257'

Test #16:

score: 11
Accepted
time: 184ms
memory: 67144kb

input:

5000 250000
-373379485 192871089
-614533315 366947758
-121723114 879673860
-651309618 520690140
-886077839 187288132
-504502031 817901566
-182786796 355657109
-994381137 875787952
-483461868 316228778
-898256952 648233057
-217482119 532821325
-291477458 583079893
-723300928 298597597
-263358584 7169...

output:

116846 36625 5714066 3471819 200665 0 1030371 59731 8387295 686368 8134 460568 3876184 430009 0 1620348 1245548 399738 1496363 1388990 1048705 664919 9657 3473278 3462664 2113143 2490030 399685 2133367 4463636 2942327 389518 460698 0 569466 0 745358 4590720 103818 0 23 0 48858 0 14626 47391 1347110 ...

result:

ok single line: '116846 36625 5714066 3471819 2... 68674 3444516 3874546 0 982069'

Test #17:

score: 11
Accepted
time: 182ms
memory: 67092kb

input:

5000 250000
-490263357 61387229
-20752762 97609940
-287598052 569376829
-481346147 568906832
-665143683 469592315
-830241592 729204414
-244986706 675450838
-772410814 953235869
-200214146 765443632
-584634742 647305810
-925194179 7744911
-71337245 804954276
-995954367 168907805
-845231659 297413952
...

output:

646164 0 278539 0 21804 786690 1821 1269105 156471 9507297 2705959 473767 0 0 172503 209100 558447 3176727 0 3069630 0 58264 82894 153775 0 4827 3590309 224012 1250976 0 947268 1410114 61560 116322 1475379 3670262 4707755 60546 447566 0 1141371 1598949 1157676 160383 167264 0 0 1408428 738537 89020 ...

result:

ok single line: '646164 0 278539 0 21804 786690...089424 0 1828935 17535 0 5768 0'

Test #18:

score: 11
Accepted
time: 173ms
memory: 64920kb

input:

5000 250000
-385864748 -303826729
-402834820 811524945
-985558315 531699356
-553860285 -402878127
-410033727 -88314660
-681742515 383677301
-578919686 562395337
-711999661 238125432
-646042673 406941194
-223327357 687596634
-15002788 413846905
-811578498 324730289
-149311836 248388032
-132072560 949...

output:

0 0 0 0 41041 29008 0 152 23 0 0 0 0 672 40716 0 0 0 0 0 0 0 1704 0 0 20793 8330 0 0 0 0 0 40376 0 0 31584 576 0 0 0 0 0 0 0 0 0 92272 280 0 0 73476 225 340 0 0 0 0 1040 0 43957 0 744 0 0 0 0 0 310 0 0 0 0 114958 12625 0 0 0 5558 0 0 85 0 0 0 0 0 12886 321 0 0 0 0 0 0 0 0 0 0 0 0 0 0 19866 3496 254 ...

result:

ok single line: '0 0 0 0 41041 29008 0 152 23 0... 0 0 1464 0 0 0 0 0 38579 86940'

Test #19:

score: 11
Accepted
time: 175ms
memory: 69016kb

input:

5000 250000
-812315904 860254861
-423485566 -202419858
-937341623 -269692032
-879599845 93308316
-90239997 979044377
-548237897 316836605
-434622741 143438388
-196892152 965709666
-365667057 -86985112
-49869940 447051181
-690716709 945611992
-695743685 734239993
-25081761 922809078
-375632267 870233...

output:

0 0 0 0 0 0 0 0 0 26201 16048 1410 0 0 4972 0 0 0 3248 0 0 0 0 0 0 0 0 0 0 0 0 0 117986 0 0 0 0 0 132 0 2880 0 0 286 0 0 0 0 0 0 2940 0 0 12285 0 0 0 0 0 0 0 11938 0 0 0 0 0 0 2600 0 0 0 0 5445 1440 0 0 0 0 0 54720 0 0 0 9056 210 8246 0 0 0 16030 0 0 1614 0 0 0 0 0 0 60876 0 0 0 0 0 480 0 1158 0 0 8...

result:

ok single line: '0 0 0 0 0 0 0 0 0 26201 16048 ...15397 27676 0 0 58176 0 0 0 0 0'

Test #20:

score: 11
Accepted
time: 167ms
memory: 64860kb

input:

5000 250000
226970229 873100310
316585143 902681355
527771722 606508476
257965805 486642272
444400073 803771543
984521958 987446635
87249376 496693035
735277017 832718558
320533681 533311182
352207220 947457352
722312212 820480721
945552983 982437353
499741202 585694600
168232087 861529294
931162475...

output:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok single line: '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0'

Subtask #3:

score: 45
Accepted

Test #21:

score: 45
Accepted
time: 157ms
memory: 105140kb

input:

250000 1
-543496082 -299601020
-39608515 549964453
-530733186 -79683976
754617266 802622468
-38898366 802488045
-364127664 -290888936
-50711383 244446176
-534113962 -186191821
-567669779 -442440583
-940710839 100015361
252145012 581983114
-675582860 977874795
-428682466 158586352
-970917601 -8489024...

output:

5566571630

result:

ok single line: '5566571630'

Test #22:

score: 45
Accepted
time: 159ms
memory: 100260kb

input:

250000 1
55833346 634174221
-723429466 277551372
-286783085 155911222
-356576692 540635648
-934424842 495687604
-351267227 652046153
-432893370 792816388
-836789001 458758025
790460867 888409331
-176867970 -120294777
-634973645 338785583
-665330259 686411826
-744463307 131880518
-708305848 -19957976...

output:

5535067443

result:

ok single line: '5535067443'

Test #23:

score: 45
Accepted
time: 217ms
memory: 111484kb

input:

250000 1
-705070118 148669035
-545941662 736352787
-131017887 548899092
-33308274 608639536
-113812616 94574483
-214787842 840432236
-179736060 154569151
-44275357 874402424
-162813663 360924866
-339355678 689498777
-732063331 537073053
-690201711 677175849
-887282822 939830180
-621184512 614487574
...

output:

31249267594

result:

ok single line: '31249267594'

Test #24:

score: 45
Accepted
time: 209ms
memory: 107340kb

input:

250000 1
-526986694 576993687
-952161109 56949560
-296892825 388345165
-598503587 246790820
-892878461 671845962
-540527402 751735084
-536903265 34171392
-972048138 951850341
-734341749 515172424
-170957660 128763018
-584999583 11996639
-175094201 899050233
-159936261 810140388
-908090291 45169331
-...

output:

31249849034

result:

ok single line: '31249849034'

Test #25:

score: 45
Accepted
time: 212ms
memory: 105416kb

input:

250000 1
-643870566 445509827
-213156363 787611742
-317543572 932823942
-428540115 589974808
-671944305 659182848
-866266962 218327532
-599103175 353965121
-455110519 29298258
-746061322 519676879
-297526938 422803067
-437935834 632144417
-659986692 561116104
-992398212 535226405
-194996070 92056148...

output:

31249782017

result:

ok single line: '31249782017'

Test #26:

score: 45
Accepted
time: 66ms
memory: 87108kb

input:

250000 1
-856517958 -619427213
-872971827 148131597
-409200739 -355899197
-589885656 579933582
-731519443 -590390548
-787398203 454132204
-248132829 354270434
-890583700 883347178
-134499882 -105606186
-120309854 972802526
-558465147 965164845
-913755500 -307879646
-269386014 932035472
-637157826 -1...

output:

454075699

result:

ok single line: '454075699'

Test #27:

score: 45
Accepted
time: 67ms
memory: 89208kb

input:

250000 1
-282969113 -149053649
-893622574 -76429575
-66016751 51240754
-915625216 413187007
-1660306 955479874
-799117777 -421308184
-954092780 38831385
-80508895 901534739
-409413865 811816125
-801628245 -353728696
-234179069 510332452
-502953391 477436938
-145155939 677989390
-25941725 10743120
-2...

output:

454307670

result:

ok single line: '454307670'

Test #28:

score: 45
Accepted
time: 42ms
memory: 84524kb

input:

250000 1
418299756 972961062
571103402 617725165
633587428 764049366
773866713 778328992
133640329 543718703
874836218 988116749
377130553 494559243
404948894 666083358
485762132 686952494
67394585 161721573
864677953 903451421
287221503 713834352
940693223 980303348
395307182 915042891
502348084 54...

output:

1

result:

ok single line: '1'

Subtask #4:

score: 12
Accepted

Test #29:

score: 12
Accepted
time: 343ms
memory: 118664kb

input:

250000 250000
-264115059 476534534
-869150566 6281702
-783550218 792380893
7506525 930311790
-646097071 -379884150
-592909389 708779219
-894131565 -642018004
-525499161 -121443011
272895987 348900763
-564676915 -98125998
-138873680 448613121
-687384430 463032687
-678754174 -221274009
-877227058 8632...

output:

0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 1 0 0 0 1 1 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 ...

result:

ok single line: '0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 ...0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0'

Test #30:

score: 12
Accepted
time: 348ms
memory: 119508kb

input:

250000 250000
-873063807 913555244
-500113177 784765285
-990649327 -226007406
178273086 848307366
-383009956 154701821
-823138743 -53318399
-102671561 975800010
-290117114 818474129
-418197788 -27935112
-982742643 863472461
106112477 240286398
716375080 726185308
-537054850 -410492713
-371525513 -19...

output:

0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 ...

result:

ok single line: '0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 ...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0'

Test #31:

score: 12
Accepted
time: 433ms
memory: 130516kb

input:

250000 250000
-54695195 137061220
-822378444 305464955
-481419494 896320381
-766409207 230962568
-937683775 211245090
-375181031 573815200
-272599553 595562956
-774981955 140020930
-255097219 862165018
-957998577 276389963
-60297240 955714126
-56942995 429960577
-872098702 30123982
-729733636 491945...

output:

1 1 0 1 1 1 1 0 1 0 0 0 0 1 0 1 0 0 0 0 0 1 1 0 1 0 1 1 1 0 0 0 1 1 1 1 0 0 1 0 0 1 1 1 0 1 1 1 1 1 0 0 1 0 1 1 1 0 0 0 0 0 0 1 0 1 1 0 1 0 1 0 0 1 1 1 1 0 1 1 0 1 0 0 1 0 1 1 1 1 0 1 0 0 1 0 1 0 1 1 1 1 0 1 0 0 0 1 0 1 0 0 1 1 0 1 1 0 0 0 0 0 0 1 0 0 1 0 0 1 1 1 1 1 0 0 1 0 0 1 1 0 1 1 0 0 0 0 1 1 ...

result:

ok single line: '1 1 0 1 1 1 1 0 1 0 0 0 0 1 0 ...0 0 0 0 1 0 0 1 1 1 1 1 0 0 0 1'

Test #32:

score: 12
Accepted
time: 424ms
memory: 131404kb

input:

250000 250000
-876611771 5577361
-228597891 476318625
-647294432 440799158
-186380328 574146556
-716749619 493549272
-700920591 630342240
-334799462 770132493
-258044336 217468847
-266816792 866669472
-84567855 420686908
-208200787 575861904
-541835485 651834960
-849784845 605466894
-721672118 72370...

output:

1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 1 0 0 0 0 1 1 1 1 1 0 0 1 0 0 1 0 1 1 0 1 1 1 0 1 0 0 0 1 0 0 1 0 0 0 0 0 0 0 1 0 0 1 1 0 1 0 0 0 1 1 1 1 1 1 0 1 0 0 1 0 0 1 0 0 1 0 1 0 1 1 0 0 0 1 1 1 1 1 1 0 0 0 1 0 0 1 1 1 1 1 0 0 0 1 0 1 0 1 1 0 0 1 0 1 0 0 0 1 1 1 0 0 1 1 0 1 0 0 1 0 0 1 0 1 1 0 0 1 0 1 1 0 0 1 ...

result:

ok single line: '1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 ...0 1 1 0 1 0 0 0 0 0 1 0 1 0 1 0'

Test #33:

score: 12
Accepted
time: 428ms
memory: 130268kb

input:

250000 250000
-698528347 433902013
-489593145 501948102
-667945179 985277935
-456608345 917330544
-790782760 775853454
-26660151 246677792
-691966668 794958926
-331041309 294916764
-838344878 20917030
-916169837 859951149
-61137039 196009681
-731760680 168676640
-417405580 330552910
-8577897 6527952...

output:

0 1 1 1 0 1 1 0 1 1 1 0 1 0 0 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 1 1 1 0 0 1 1 1 0 1 1 0 0 0 1 0 0 0 0 1 0 0 0 1 1 1 1 1 1 0 1 0 1 0 1 0 0 0 0 0 1 0 1 1 1 1 0 1 0 0 1 0 1 0 1 0 1 0 1 1 1 0 1 0 0 1 1 0 1 0 0 0 1 1 0 1 0 1 0 0 0 1 0 0 1 1 1 1 0 1 0 1 1 1 0 1 1 1 1 0 1 1 0 1 0 1 0 1 1 0 1 1 1 1 1 0 1 ...

result:

ok single line: '0 1 1 1 0 1 1 0 1 1 1 0 1 0 0 ...0 1 0 0 0 1 0 1 0 1 0 1 1 0 0 0'

Test #34:

score: 12
Accepted
time: 241ms
memory: 117224kb

input:

250000 250000
-868125772 -344577859
-928406138 860906090
-227069196 726575602
-455311549 -297483159
-440268742 1582931
-319873247 520948891
-661241643 423829248
-962357688 -99002542
-339173376 456179104
-991374207 561898442
-562635621 -338871542
-489878510 36970198
-264286683 33119279
-812463915 519...

output:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok single line: '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0'

Test #35:

score: 12
Accepted
time: 239ms
memory: 116516kb

input:

250000 250000
-294576928 304118881
-949056885 349300456
-883885208 181561178
-76018405 621125504
-265699205 -136091344
-36625525 437055645
-662168890 449579234
-447250179 817739047
-763830463 -11633707
-817916791 477602624
-93125351 548976427
-374043698 -275190228
-140056608 185161665
-496215110 -39...

output:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok single line: '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0'

Test #36:

score: 12
Accepted
time: 209ms
memory: 105420kb

input:

250000 250000
363641975 792900290
294666621 306766820
578153117 623364312
185989971 412509063
309769170 324345805
714443029 739522627
579234356 760739322
118952696 179482100
248254385 995278668
153784390 977604540
946509452 965579624
215447515 483070222
955877343 992335226
286758059 953875731
486059...

output:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok single line: '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0'

Subtask #5:

score: 27
Accepted

Test #37:

score: 27
Accepted
time: 426ms
memory: 123124kb

input:

250000 250000
-227823829 -157395325
-485523548 596274679
410462264 807550835
-787609417 567949227
-963959725 -389649479
-821691114 -534642419
-84586806 714797874
-273794568 -56694201
-643448456 845274815
718753308 744458843
602212442 645081231
-942578243 -693319062
-65743053 240815510
575327378 6265...

output:

15980394 1478761837 629822081 829743276 3456497806 733621020 253855858 339469873 1174898286 0 3151881315 0 46301849 2455771589 0 123564401 1224468473 183576557 658678287 906299 0 2794275858 0 76783310 91137392 0 266120451 598510898 2575188417 62415816 1717559102 709659000 120525247 0 1324962758 1417...

result:

ok single line: '15980394 1478761837 629822081 ...4836 1481713698 0 0 0 228417691'

Test #38:

score: 27
Accepted
time: 427ms
memory: 118900kb

input:

250000 250000
198039041 949846474
241082534 965312067
-902893328 895419019
-189898368 353967610
-724341049 -126562365
703259964 948079533
332615888 411905903
-281502313 883222939
-164913527 812630654
-140157802 441869977
-614744317 731721801
-439976669 765958790
-381523894 752166762
-572802265 -4285...

output:

773684076 319584503 469682165 0 931128680 1479002926 1119384728 1416274271 643597523 71694327 389181 298172736 24986863 61468460 5366716 51421416 11813071 165393902 997199262 400818698 167457299 41160015 1480695838 280795095 155634797 0 72714993 289100375 783681438 0 0 130348085 163877083 0 13391063...

result:

ok single line: '773684076 319584503 469682165 ...107862363 0 875827632 224864654'

Test #39:

score: 27
Accepted
time: 522ms
memory: 130972kb

input:

250000 250000
-259096081 125453406
-98815226 314768611
-831821101 653807078
-649253245 413094111
-761554933 32948400
-390350027 307198165
-925271558 331524057
-60978153 815704843
-492604966 508629361
-726384580 568313853
-978465740 519579390
-983492791 332488409
-297106071 825450488
-248348167 22417...

output:

0 0 267615154 1598275173 0 1568562478 627895455 343641 185224592 67051537 22054253392 0 11091164421 756264343 66436394 3547518524 5427256291 2479702607 0 3073139580 1038833438 1995304934 10224551605 354089575 669050720 781176095 7376271500 10889530019 12539901942 2203259114 249411890 0 14639229525 2...

result:

ok single line: '0 0 267615154 1598275173 0 156...5245014323 3002072485 336987979'

Test #40:

score: 27
Accepted
time: 534ms
memory: 126976kb

input:

250000 250000
-786045361 699002250
-359810480 45430793
-702728744 198285855
-919481261 756278099
-835588074 315252582
-11056884 363725204
-282438763 61383194
-839007830 893152760
-209357244 367909624
-852953858 7578094
-831401992 139727168
-613609473 699586984
-274792214 400793400
-535253946 5096367...

output:

1249375599 0 3134371616 0 270264834 5780302673 3658491705 1628432388 2825870016 1205749218 9446840006 0 2765118711 16943985945 0 0 0 664785998 1147774940 1974925656 3384472129 7266644833 9779750056 5570225586 6347979511 0 2601100393 0 2080088827 92168885 2627928120 8856785 428608924 369818876 492755...

result:

ok single line: '1249375599 0 3134371616 0 2702... 555212248 522498540 9304360290'

Test #41:

score: 27
Accepted
time: 522ms
memory: 128396kb

input:

250000 250000
-902929233 272551095
-60997223 71060271
-723379490 182956119
-44485086 99462087
-614653918 597556764
-41829148 125284948
-489862865 235952731
-471813315 970600677
-370819922 962348670
-684555840 856907743
-834081347 759874946
-393469260 216428663
-252478357 125879416
-527192429 5302531...

output:

373351905 772714027 48667182 8357070174 88836104 1250787625 3625751433 0 929847533 230931525 11802249820 5258210376 1842217050 474880053 891960720 1690362432 571834762 7774802733 3644216712 594013095 1372166000 420032836 8486049711 600664004 0 213586688 19701768435 678652039 8733024092 5193906409 27...

result:

ok single line: '373351905 772714027 48667182 8...250432125 6009573506 3496334372'

Test #42:

score: 27
Accepted
time: 309ms
memory: 112700kb

input:

250000 250000
-879733586 111937848
-133583554 348030984
-899713460 -645752921
-765447842 -358065674
-704307641 74093753
-557380995 -287065941
-369317753 511547691
-34131677 515777392
-543846870 -533680952
-712695457 -459481185
-421581904 -202079419
-655936113 -435015092
-109444248 -92722179
-4279614...

output:

0 0 0 0 0 67530525 0 0 103591908 0 0 0 0 93482000 0 0 0 0 0 314444676 0 0 0 0 0 0 0 0 220371366 0 0 0 0 0 30635696 0 0 44648651 0 0 0 0 0 0 0 65590470 0 0 0 0 0 0 0 0 4273018 0 0 0 0 0 0 0 0 0 0 0 0 83935767 0 0 25493292 340924290 57561021 0 0 0 0 0 0 0 0 74809008 0 0 339422 0 0 5088547 0 0 0 0 9008...

result:

ok single line: '0 0 0 0 0 67530525 0 0 1035919...8914231 0 0 219122610 6105000 0'

Test #43:

score: 27
Accepted
time: 308ms
memory: 112660kb

input:

250000 250000
-306184742 19710123
-4491196 562167176
-261562176 592100114
-91187402 29054424
-824705400 528233072
-423876377 174978507
-75277704 119406283
-519024167 721002875
-968503958 319866761
-688981144 -282295684
-952071633 -850103254
-950166708 644851084
-985214173 -198687104
-376553903 82200...

output:

0 0 0 0 0 0 0 14465194 0 5221290 0 0 329354560 0 10052889 0 0 0 0 0 0 0 0 0 0 88002335 0 88720775 0 0 44259600 0 0 0 267322302 0 0 0 0 0 0 0 2751570 0 0 0 0 7818990 0 0 0 0 0 0 0 22319568 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 268759506 0 0 0 201239808 23358930 0 1748490 1009020 0 0 28160055 0 0 16149946...

result:

ok single line: '0 0 0 0 0 0 0 14465194 0 52212...8 0 0 0 147199350 0 0 0 0 0 0 0'

Test #44:

score: 27
Accepted
time: 263ms
memory: 104584kb

input:

250000 250000
159241090 806194493
868486735 910614418
227751509 852835353
452889038 982903360
190930716 912017058
699274032 996198700
631595055 992680375
683213394 932883194
10746637 347713116
680365683 704148197
323308248 902849524
553738935 752667750
825837270 998811642
768143527 857832850
9099624...

output:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok single line: '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0'