QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#447281#7417. Honorable MentionzhaohaikunAC ✓1017ms106844kbC++205.7kb2024-06-18 08:42:092024-06-18 08:42:12

Judging History

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

  • [2024-06-18 08:42:12]
  • 评测
  • 测评结果:AC
  • 用时:1017ms
  • 内存:106844kb
  • [2024-06-18 08:42:09]
  • 提交

answer

#include <bits/stdc++.h>
#define ls num << 1
#define rs ls | 1
#define li ls, l, mid
#define ri rs, mid + 1, r
#define SZ(x) (int) x.size() - 1
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> void chkmax(T& x, T y) { x = max(x, y); }
template <typename T> void chkmin(T& x, T y) { x = min(x, y); }
template <typename T> void read(T &x) {
	x = 0; int f = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	x *= f;
}
const int N = 5e4 + 10;
int num, n, q, a[N];
struct point {
    int x; ll y;
    friend point operator + (const point &a, const point &b) {
        return {a.x + b.x, a.y + b.y};
    }
    friend point operator - (const point &a, const point &b) {
        return {a.x - b.x, a.y - b.y};
    }
    friend ll operator * (const point &a, const point &b) {
        return a.x * b.y - a.y * b.x;
    }
    friend bool operator > (const point &a, const point &b) {
        return a * b <= 0;
    }
};
int K;
struct hull {
    vector <point> x;
    int pos;
    hull () {
        pos = 0;
    }
    friend hull operator + (const hull &x, const hull &y) {
        hull ans; ans.x.resize(x.x.size() + y.x.size() - 1);
        ans.x[0]= x.x[0] + y.x[0];
        unsigned l = 0, r = 0;
        while (l < SZ(x.x) && r < SZ(y.x)) {
            point A = x.x[l + 1] - x.x[l], B = y.x[r + 1] - y.x[r];
            if (A > B) ans.x[l + r + 1] = ans.x[l + r] + A, l++;
            else ans.x[l + r + 1] = ans.x[l + r] + B, r++;
        }
        while (l < SZ(x.x)) ans.x[l + r + 1] = ans.x[l + r] + x.x[l + 1] - x.x[l], l++;
        while (r < SZ(y.x)) ans.x[l + r + 1] = ans.x[l + r] + y.x[r + 1] - y.x[r], r++;
        return ans;
    }
    friend hull operator + (hull x, const point &y) {
        for (point &i: x.x) i = i + y;
        return x;
    }
    friend hull operator * (const hull &x, const hull &y) {
        hull ans; ans.x.resize(x.x.size() + y.x.size());
        unsigned l = 0, r = 0; int sz = -1;
        while (l < x.x.size() || r < y.x.size()) {
            point tmp;
            if (r != y.x.size() && (l == x.x.size() || (x.x[l].x > y.x[r].x || (x.x[l].x == y.x[r].x && x.x[l].y > y.x[r].y)))) tmp = y.x[r], r++;
            else tmp = x.x[l], l++;
            while (sz >= 1 && tmp - ans.x[sz] > ans.x[sz] - ans.x[sz - 1]) sz--;
            ans.x[++sz] = tmp;
        }
        ans.x.resize(sz + 1);
        return ans;
    }
    ll qq(const point &x) {
        return (ll) x.x * K + x.y;
    }
    point qry() {
		// cout << "# " << pos << endl;
        while (pos < SZ(x) && qq(x[pos]) < qq(x[pos + 1])) pos++;
        return {x[pos].x, qq(x[pos])};
    }
};
struct ment {
    hull lans, rans, lrans, ans;
    friend ment operator + (const ment &x, const ment &y) {
        return {(x.lans + y.ans) * (x.lrans + y.lans + (point) {-1, 0}),
        (y.rans + x.ans) * (y.lrans + x.rans + (point) {-1, 0}),
        (x.lans + y.rans) * (x.lrans + y.lrans + (point) {-1, 0}),
		(x.ans + y.ans) * (x.rans + y.lans + (point) {-1, 0})};
    }
} seg[N << 2];
void build(int num, int l, int r) {
	if (l == r) {
		seg[num].lans.x = seg[num].rans.x = seg[num].lrans.x = vector{(point) {1, a[l]}};
		seg[num].ans.x = vector{(point) {0, 0}, (point) {1, a[l]}};
		return;
	}
	int mid = (l + r) >> 1;
	build(li), build(ri);
	seg[num] = seg[ls] + seg[rs];
	// for (point i: seg[ls].rans.x) cout << num << " " << l << " " << r << " -> " << i.x << " " << i.y << endl;
	// for (point i: seg[rs].lans.x) cout << num << " " << l << " " << r << " -> " << i.x << " " << i.y << endl;
}
struct QQ {
	int l, r, k, id;
	int tl, tr, mid;
} Q[N];
point Max(point x, point y) {
	if (x.y != y.y)
	return x.y > y.y ? x : y;
	return x.x < y.x ? x : y;
}
struct P {
	point lans, rans, lrans, ans;
	friend P operator + (P x, P y) {
		return {Max(x.lans + y.ans, x.lrans + y.lans + (point) {-1, -K}), Max(y.rans + x.ans, y.lrans + x.rans + (point) {-1, -K}), Max(x.lans + y.rans, x.lrans + y.lrans + (point) {-1, -K}), Max(x.ans + y.ans, x.rans + y.lans + (point) {-1, -K})};
	}
};
P query(int num, int l, int r, int L, int R) {
	if (L <= l && r <= R) {
		// P x = 
		return {seg[num].lans.qry(), seg[num].rans.qry(), seg[num].lrans.qry(), seg[num].ans.qry()};
		// cout << num << " " << l << " " << r << " " << x.ans.x << " % " << x.ans.y << endl;
		// return x;
	}
	int mid = (l + r) >> 1;
	if (mid >= R) return query(li, L, R);
	if (mid < L) return query(ri, L, R);
	return query(li, L, R) + query(ri, L, R);
}
ll ans[N];
signed main() {
	read(n), read(q);
	F(i, 1, n) read(a[i]);
	build(1, 1, n);
	// for (point x: seg[1].ans.x) cout << "! " << x.x << " " << x.y << endl;
	// return 0;
	F(i, 1, q) read(Q[i].l), read(Q[i].r), read(Q[i].k), Q[i].tl = -1e9, Q[i].tr = 1e9, Q[i].id = i;
	while (true) {
		bool flag = true;
		F(i, 1, q) Q[i].mid = (Q[i].tl + Q[i].tr) >> 1;
		F(i, 1, n * 4) seg[i].ans.pos = seg[i].lans.pos = seg[i].rans.pos = seg[i].lrans.pos = 0;
		sort(Q + 1, Q + q + 1, [&] (QQ x, QQ y) {
			return x.mid < y.mid;
		});
		F(i, 1, q) {
			if (Q[i].tl + 1 < Q[i].tr) {
				flag = false;
				K = Q[i].mid;
				P t = query(1, 1, n, Q[i].l, Q[i].r);
				// cout << "# " << K << " " << t.ans.x << " " << t.ans.y << endl;
				if (t.ans.x <= Q[i].k) Q[i].tl = K, ans[Q[i].id] = t.ans.y - (ll) K * Q[i].k;
				else Q[i].tr = K;
			}
		}
		if (flag) break;
	}
	F(i, 1, q) cout << ans[i] << '\n';
	return 0;
}
// inaugurate

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

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

input:

5 5
-1 2 -3 4 -5
1 5 1
1 5 2
1 5 3
1 5 4
1 5 5

output:

4
6
5
2
-3

result:

ok 5 number(s): "4 6 5 2 -3"

Test #2:

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

input:

5 1
7 7 7 7 7
1 5 1

output:

35

result:

ok 1 number(s): "35"

Test #3:

score: 0
Accepted
time: 625ms
memory: 73052kb

input:

25000 25000
-11889 -16468 18402 -13238 14125 12120 -3295 -12106 20152 7478 8575 9968 -13946 -13408 23715 -14670 -21837 12589 7029 20609 2868 12728 -6942 982 5884 -7561 -2058 -7892 7806 16344 14645 13904 7355 9860 15446 -539 24072 21969 19028 -24939 -21911 -11836 21045 -4727 -3882 2138 18513 -4796 -1...

output:

10341941
44514177
6687268
77971944
99605102
107722534
15473041
17383093
62015893
10703102
41214044
22949449
9407209
9022260
39351814
72311292
5178065
42027491
52700848
38135774
37045964
4761513
16326256
16812496
107985169
28306484
46710957
864270
102812861
27960495
50366764
16379719
2791377
21112728...

result:

ok 25000 numbers

Test #4:

score: 0
Accepted
time: 632ms
memory: 72532kb

input:

25000 25000
6000 -3019 -11754 -7445 -8441 7523 7149 -9202 7895 12217 7475 3656 1303 1710 9238 7029 5141 -1777 8992 -2357 5436 8102 4094 -10002 -7052 3213 1387 -41 -5364 -8259 4860 -721 12482 3791 6804 -10687 4462 -7578 -12456 5135 10987 -9087 5706 -8716 10036 9149 -11514 -7407 4623 9555 -4053 6603 -...

output:

34173465
3726494
235962
7075586
30183529
3643608
48804222
7114899
4984843
15646757
1887647
2330595
47535902
239762
6115278
7951919
1734323
2623203
1495055
1420131
10657149
3064884
12169559
9504529
617684
25801604
3732771
6630548
9892438
1190577
24266894
3527999
23386393
33402029
16816797
62284476
37...

result:

ok 25000 numbers

Test #5:

score: 0
Accepted
time: 619ms
memory: 70880kb

input:

25000 25000
-2969 1681 -2312 -367 -2816 2496 -2066 -636 182 -522 1159 3035 -1616 -2017 -727 -64 987 -3044 -721 1871 -465 452 -2136 -636 1252 2947 -2252 -602 1521 1299 -3070 100 -3111 -1212 -1211 132 2798 -467 1610 408 491 520 2182 2323 2984 -1105 458 -384 917 165 1019 -1424 -1740 1838 225 1043 -1643...

output:

3696093
5856268
1569949
43110
361033
1251419
5991586
11948087
10350223
3152434
10667775
4975400
8739958
9585292
6671359
6889903
10775826
200001
7290024
4142281
7861955
7191701
644506
803034
1932372
9842195
6618617
12318124
4618343
5306047
12502164
612289
2157188
11618855
7200073
5016967
2463491
3209...

result:

ok 25000 numbers

Test #6:

score: 0
Accepted
time: 605ms
memory: 68768kb

input:

25000 25000
-240 -760 1554 200 279 1306 -394 1272 967 -1151 -13 1286 994 1110 551 445 1428 -175 -1427 854 927 911 -969 -920 968 -913 -1481 -669 1487 -600 291 -1070 -782 1504 -222 599 -939 1194 1129 -397 -185 627 772 -870 133 -695 -1092 -137 -778 1332 -158 1545 -329 273 1098 -671 947 -1095 257 -1024 ...

output:

5052771
5348425
6990219
1782518
4288908
124491
4603645
662433
3354133
2273603
2117016
908991
3981909
181606
180388
1445473
8334703
3417019
3832988
1156373
751967
816152
207595
5328156
304047
4822038
8095611
4532395
4836019
4415840
779952
5397423
5924339
1559505
2746919
3784667
3664365
1427979
207448...

result:

ok 25000 numbers

Test #7:

score: 0
Accepted
time: 574ms
memory: 65784kb

input:

25000 25000
-235 -315 120 -376 455 154 461 150 -280 -74 -242 -432 -50 25 -303 -327 263 499 -464 -203 333 59 -265 -72 357 -213 2 275 -159 -4 160 -304 -320 103 447 382 -120 -65 364 -351 73 -307 284 -469 -118 -324 -310 93 -347 -48 -286 139 -25 401 105 -479 -377 428 -26 -313 97 -132 78 14 -64 -59 -455 -...

output:

166178
1692049
770543
2394705
1908039
1005349
356998
25023
355550
891075
214103
788750
1008340
1536696
160682
151535
300585
373884
849931
800218
2440857
1009992
311596
635872
2502637
288362
284558
538137
1553207
849175
165203
544829
230264
163844
1284945
801960
371289
637139
1249915
203702
12408
830...

result:

ok 25000 numbers

Test #8:

score: 0
Accepted
time: 570ms
memory: 62288kb

input:

25000 25000
163 -18 16 -124 54 -71 -111 -81 46 27 139 16 -51 -78 36 21 85 -31 49 33 -42 -42 122 81 -25 -43 166 -131 2 -45 154 -68 -76 127 48 124 92 -26 128 44 -22 -95 -80 -52 -64 -113 22 104 -76 58 49 53 -115 70 -159 -67 62 83 69 164 -11 -13 -4 81 -82 -98 68 136 -7 146 17 138 89 89 18 57 143 57 51 1...

output:

494541
25814
267902
153374
150628
206276
98909
261258
5231
645604
828846
372159
655216
2523
152068
199639
515692
443552
753836
15295
70205
795943
704318
398355
396254
15170
495548
103742
129088
19442
870390
146159
8499
270179
380106
191900
682344
4356
559722
372147
426880
529125
46890
161656
291764
...

result:

ok 25000 numbers

Test #9:

score: 0
Accepted
time: 521ms
memory: 55620kb

input:

25000 25000
10 9 3 19 -1 -5 26 11 3 15 -1 -9 23 11 -24 12 -3 21 -20 10 -10 12 -19 -16 11 -2 19 20 18 -23 27 -23 9 2 1 1 16 -24 -23 -10 -13 21 6 -1 -20 -24 -17 20 23 12 -25 -13 -3 -20 13 24 -27 20 19 5 7 7 9 -24 15 17 -27 16 -13 -15 16 -4 7 13 5 -2 16 25 10 -3 -20 -11 22 -1 -5 -16 19 4 -19 15 5 -25 5...

output:

54921
58348
91837
2814
18931
43185
74327
16895
936
59014
117622
124161
120167
3943
29622
6749
86196
11513
98358
48694
34346
87327
44195
21361
94794
23566
21059
113460
121018
5009
2641
1200
27270
37878
32708
43496
39506
33574
58612
6251
5481
10564
78957
79670
49585
21564
100771
40511
716
93538
21835
...

result:

ok 25000 numbers

Test #10:

score: 0
Accepted
time: 494ms
memory: 50896kb

input:

25000 25000
-1 6 4 3 5 5 3 4 6 -4 0 -5 3 -6 6 3 5 5 -3 3 6 2 -3 4 -4 0 6 -1 -4 -3 1 -1 -3 -3 -5 0 1 2 -4 -1 -6 5 -6 -4 0 4 -6 1 -1 -1 -4 3 -4 -2 0 4 -3 -2 -3 0 5 -4 -5 -2 -6 0 5 3 -4 -2 -4 0 -3 -6 -6 -5 -3 4 3 -1 -3 -2 -1 -4 3 -3 -3 -5 1 1 -3 -2 1 -3 3 6 -4 0 -6 -4 -2 -6 -1 -2 0 -1 2 -5 -4 -5 -4 -5 ...

output:

3471
9242
14877
3247
25345
1268
12419
4913
9553
3945
12865
6204
24807
103
6552
27546
24866
17021
9674
9271
32781
18711
2582
18824
31679
7479
1569
15391
21198
19186
4196
13914
284
15798
6722
1620
34719
122
33294
1652
5213
16791
20
26381
15749
1627
3923
13190
2548
3981
10159
10964
8728
2814
6359
5167
...

result:

ok 25000 numbers

Test #11:

score: 0
Accepted
time: 452ms
memory: 47472kb

input:

25000 25000
1 1 0 -1 1 1 -1 -1 -1 -1 1 -1 -1 1 1 -1 1 1 -1 -1 1 0 0 -1 -1 -1 -1 -1 1 -1 0 0 -1 1 0 -1 -1 -1 1 -1 1 0 0 1 -1 -1 -1 0 0 0 -1 0 1 -1 1 -1 -1 0 1 1 0 0 0 1 -1 -1 1 1 1 -1 -1 1 1 0 1 1 -1 0 0 1 0 -1 0 -1 -1 0 0 0 -1 1 0 1 0 1 -1 0 0 1 -1 1 -1 -1 0 -1 -1 1 -1 -1 -1 0 -1 1 1 1 -1 -1 -1 1 -1...

output:

3301
6509
1457
3030
6452
5069
2015
1503
25
1728
3800
117
2258
1451
4167
1618
4122
621
741
2797
1172
69
2098
2213
2771
647
5016
2385
2174
992
1724
289
482
291
6135
4240
2734
1510
4180
7432
7297
1991
929
2836
2507
1868
5223
331
3878
1157
333
533
78
2445
1960
6431
1883
215
525
1894
2587
543
5248
40
642...

result:

ok 25000 numbers

Test #12:

score: 0
Accepted
time: 95ms
memory: 74324kb

input:

25000 25000
-11889 -16468 18402 -13238 14125 12120 -3295 -12106 20152 7478 8575 9968 -13946 -13408 23715 -14670 -21837 12589 7029 20609 2868 12728 -6942 982 5884 -7561 -2058 -7892 7806 16344 14645 13904 7355 9860 15446 -539 24072 21969 19028 -24939 -21911 -11836 21045 -4727 -3882 2138 18513 -4796 -1...

output:

87051882
127416946
156123379
155327388
86540841
156123379
152788996
131969751
156123379
111716016
156123379
155098177
82033347
121443037
152920829
57710183
128591152
156123379
135344755
155722784
156123379
155964587
121111574
128072179
148457241
152720039
78217004
152102942
129197020
68552217
156123...

result:

ok 25000 numbers

Test #13:

score: 0
Accepted
time: 131ms
memory: 30420kb

input:

220 24310
13015 261 15901 -7125 -14419 17435 9913 -24051 18306 -4428 480 -13711 19396 -11292 6420 3248 -8598 6774 -17293 3239 -5108 5952 303 16071 -22557 -4018 -13295 -7069 -4337 11124 22372 22680 -3536 5727 4068 8908 18992 5457 -22918 11369 7680 11365 658 22588 -3283 1458 19818 -1087 -19664 1304 72...

output:

13015
13276
29177
22052
29177
39487
34981
56525
67706
74831
25288
75311
34981
19681
96699
94227
92822
79706
76568
110669
113908
83789
94227
136714
136234
107437
136234
132995
123931
14588
91229
113483
135027
194898
202685
97364
230585
153099
219723
194686
219470
266456
255223
289702
282447
291160
27...

result:

ok 24310 numbers

Test #14:

score: 0
Accepted
time: 82ms
memory: 30384kb

input:

50 22100
-23471 13052 18402 -20178 -24628 18640 -24823 -8987 -2228 -24038 -243 -9695 4981 -13086 1640 12540 613 -507 1047 7164 7296 -12896 4137 7502 -10274 -21351 184 19334 20618 -17974 17474 7521 -11638 660 5685 5356 -16986 18157 -5277 -12480 -4500 15565 18886 -8383 13116 -13244 14405 19401 34 1679...

output:

-23471
13052
-10419
31454
31454
7983
31454
31454
11276
-12195
31454
31454
11276
-12195
-36823
31454
50094
50094
29916
6445
-18183
31454
50094
50094
29916
6445
-18183
-43006
31454
50094
50094
41107
20929
-2542
-27170
-51993
31454
50094
50094
47866
38879
18701
-4770
-29398
-54221
31454
50094
50094
478...

result:

ok 22100 numbers

Test #15:

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

input:

110 6105
-7687 1773 5157 4940 16237 -9474 -119 -4234 -18270 21374 3158 -23669 -673 -16011 10637 22861 13718 -6785 -7470 14415 1147 24431 -20309 7711 3538 17699 20859 13405 -12577 -20900 -2283 10297 -620 -15121 19317 12298 -16159 -271 -13895 -1704 11284 3415 -12854 9716 -19969 -2837 -19233 -5611 8865...

output:

-7687
1773
6930
11870
20420
28107
10827
28107
-11677
45128
52639
48286
12182
-27498
41089
85345
99855
47216
99063
94989
78975
139848
112880
147559
151097
54095
177844
202268
75782
99451
76268
210282
213357
213357
165631
123339
244972
161647
131593
115857
256256
220420
259671
81971
249374
138613
1386...

result:

ok 6105 numbers

Test #16:

score: 0
Accepted
time: 9ms
memory: 29460kb

input:

25 2925
8168 21503 6660 -24371 5153 3918 18114 16071 10658 3262 -10966 -18114 654 14490 -22078 -742 -1473 10374 -22200 -11725 -17719 -7231 17613 -24337 -21671
1 1 1
1 2 1
1 2 2
1 3 1
1 3 2
1 3 3
1 4 1
1 4 2
1 4 3
1 4 4
1 5 1
1 5 2
1 5 3
1 5 4
1 5 5
1 6 1
1 6 2
1 6 3
1 6 4
1 6 5
1 6 6
1 7 1
1 7 2
1 7...

output:

8168
29671
29671
36331
36331
36331
36331
36331
36331
11960
36331
41484
41484
41484
17113
36331
45402
45402
45402
45402
21031
39145
63516
63516
63516
63516
63516
39145
55216
79587
79587
79587
79587
79587
79587
55216
65874
90245
90245
90245
90245
90245
90245
90245
65874
69136
93507
93507
93507
93507
9...

result:

ok 2925 numbers

Test #17:

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

input:

55 1540
-5022 -13580 742 19398 4619 12430 23764 21928 -22180 -14511 16789 -7694 -14808 13025 -13950 -1672 1812 -8599 15352 -19933 -6195 20307 -8942 -4334 -20497 -16858 -20262 7431 -24205 3040 -11312 350 17288 16769 -13397 14736 -18631 -23967 -2359 -17069 11308 13022 -4595 -24151 -16641 14098 -15015 ...

output:

-5022
-5022
742
20140
6157
32167
60953
82881
64279
82881
99670
73374
94648
57080
57938
82881
114507
114507
129859
79342
129859
150166
84512
150166
65667
82881
139138
87609
41432
4277
148354
148354
165992
27372
195044
197497
208108
82881
-34956
171075
221088
142957
221150
234110
230079
66670
207738
2...

result:

ok 1540 numbers

Test #18:

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

input:

12 364
-1467 -5769 -9510 6456 23487 -17009 -14865 -7051 17960 10027 7039 -12853
1 1 1
1 2 1
1 2 2
1 3 1
1 3 2
1 3 3
1 4 1
1 4 2
1 4 3
1 4 4
1 5 1
1 5 2
1 5 3
1 5 4
1 5 5
1 6 1
1 6 2
1 6 3
1 6 4
1 6 5
1 6 6
1 7 1
1 7 2
1 7 3
1 7 4
1 7 5
1 7 6
1 7 7
1 8 1
1 8 2
1 8 3
1 8 4
1 8 5
1 8 6
1 8 7
1 8 8
1 9 ...

output:

-1467
-1467
-7236
-1467
-7236
-16746
6456
4989
-780
-10290
29943
29943
28476
22707
13197
29943
29943
28476
22707
13197
-3812
29943
29943
28476
22707
13197
-1668
-18677
29943
29943
28476
22707
15656
6146
-8719
-25728
29943
47903
47903
46436
40667
33616
24106
9241
-7768
29943
57930
57930
57930
56463
5...

result:

ok 364 numbers

Test #19:

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

input:

27 378
9624 -7800 13317 1459 -12176 -9916 4206 -13719 9929 7429 -11783 127 16270 14935 8560 13763 -10022 836 22740 23338 24563 23917 -10605 21524 -24173 20079 -259
1 1 1
1 2 1
1 3 2
1 4 2
1 5 3
1 6 5
1 7 3
1 8 4
1 9 2
1 10 8
1 11 11
1 12 11
1 13 6
1 14 6
1 15 8
1 16 11
1 17 14
1 18 1
1 19 9
1 20 8
1...

output:

9624
9624
22941
24400
24400
6684
28606
28606
26529
28248
-9430
4416
62361
77296
85856
99619
71881
59230
123195
146533
120685
195013
183007
204531
166411
236616
228557
-7800
13317
14776
14776
14776
11182
-24629
-981
-7271
17358
36467
52737
67672
76232
89995
89995
89995
113571
136909
161472
144602
167...

result:

ok 378 numbers

Test #20:

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

input:

6 56
8756 12932 2360 -14266 8455 17093
1 1 1
1 2 1
1 2 2
1 3 1
1 3 2
1 3 3
1 4 1
1 4 2
1 4 3
1 4 4
1 5 1
1 5 2
1 5 3
1 5 4
1 5 5
1 6 1
1 6 2
1 6 3
1 6 4
1 6 5
1 6 6
2 2 1
2 3 1
2 3 2
2 4 1
2 4 2
2 4 3
2 5 1
2 5 2
2 5 3
2 5 4
2 6 1
2 6 2
2 6 3
2 6 4
2 6 5
3 3 1
3 4 1
3 4 2
3 5 1
3 5 2
3 5 3
3 6 1
3 6...

output:

8756
21688
21688
24048
24048
24048
24048
24048
24048
9782
24048
32503
32503
32503
18237
35330
49596
49596
49596
49596
35330
12932
15292
15292
15292
15292
1026
15292
23747
23747
9481
26574
40840
40840
40840
26574
2360
2360
-11906
8455
10815
-3451
25548
27908
27908
13642
-14266
8455
-5811
25548
25548
...

result:

ok 56 numbers

Test #21:

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

input:

13 91
-7610 -22851 9518 -5629 5994 17246 12482 1098 4326 16079 -11499 21268 -14668
1 1 1
1 2 2
1 3 3
1 4 2
1 5 1
1 6 3
1 7 2
1 8 4
1 9 7
1 10 5
1 11 8
1 12 4
1 13 7
2 2 1
2 3 1
2 4 1
2 5 3
2 6 4
2 7 5
2 8 4
2 9 1
2 10 4
2 11 1
2 12 11
2 13 4
3 3 1
3 4 2
3 5 1
3 6 2
3 7 4
3 8 6
3 9 3
3 10 7
3 11 8
3 ...

output:

-7610
-30461
-20943
3889
9883
32758
45240
46338
45035
66743
61114
88011
88011
-22851
9518
9518
9883
27129
39611
46338
45035
66743
61114
48032
88011
9518
3889
9883
32758
45240
40709
50664
66743
61114
88011
56215
-5629
5994
23240
35722
36820
35517
51596
57225
78493
46697
5994
23240
35722
36820
41146
5...

result:

ok 91 numbers

Test #22:

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

input:

3 10
23162 -8341 8074
1 1 1
1 2 1
1 2 2
1 3 1
1 3 2
1 3 3
2 2 1
2 3 1
2 3 2
3 3 1

output:

23162
23162
14821
23162
31236
22895
-8341
8074
-267
8074

result:

ok 10 numbers

Test #23:

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

input:

6 21
8756 12932 2360 -14266 8455 17093
1 1 1
1 2 1
1 3 1
1 4 2
1 5 3
1 6 3
2 2 1
2 3 1
2 4 2
2 5 3
2 6 5
3 3 1
3 4 1
3 5 1
3 6 4
4 4 1
4 5 2
4 6 1
5 5 1
5 6 1
6 6 1

output:

8756
21688
24048
24048
32503
49596
12932
15292
15292
23747
26574
2360
2360
8455
13642
-14266
-5811
25548
8455
25548
17093

result:

ok 21 numbers

Test #24:

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

input:

1 1
-9693
1 1 1

output:

-9693

result:

ok 1 number(s): "-9693"

Test #25:

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

input:

1 1
0
1 1 1

output:

0

result:

ok 1 number(s): "0"

Test #26:

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

input:

1 1
-25000
1 1 1

output:

-25000

result:

ok 1 number(s): "-25000"

Test #27:

score: 0
Accepted
time: 536ms
memory: 72856kb

input:

25000 25000
-11889 -16468 18402 -13238 14125 12120 -3295 -12106 20152 7478 8575 9968 -13946 -13408 23715 -14670 -21837 12589 7029 20609 2868 12728 -6942 982 5884 -7561 -2058 -7892 7806 16344 14645 13904 7355 9860 15446 -539 24072 21969 19028 -24939 -21911 -11836 21045 -4727 -3882 2138 18513 -4796 -1...

output:

3427020
9548677
2465819
5386512
14507180
5140459
6322722
9256176
13018451
4476928
2582098
4526086
4851441
6994265
9255914
5587353
2589713
4393603
4387380
18101413
9422571
4761513
1875134
1191260
10520221
9277010
7632712
1728700
7599991
9869123
13004206
7049064
1831443
6845552
4088258
858894
4641873
...

result:

ok 25000 numbers

Test #28:

score: 0
Accepted
time: 601ms
memory: 82080kb

input:

25000 25000
-4921 548 -2803 23419 -17668 13732 -107 8299 -14201 17755 -6220 9108 -4640 12402 -2358 18287 -14969 9819 -4614 9826 -2932 21905 -15168 2660 -2985 15059 -16777 21650 -17993 24966 -7943 5452 -1922 18401 -5770 14852 -748 3672 -5821 18493 -10432 19409 -6965 10586 -13130 3445 -4324 18616 -223...

output:

8803562
34485661
19062236
77351055
74961391
109218316
8319525
34930500
63214995
11070629
51202592
13415268
2345577
17708994
39937088
87898658
4488286
70683641
50622076
73822715
37677706
2484644
29524892
2240013
105710598
69488066
71258230
1252661
77532468
36766362
57575447
13512388
464240
7393955
10...

result:

ok 25000 numbers

Test #29:

score: 0
Accepted
time: 76ms
memory: 83172kb

input:

25000 25000
-4921 548 -2803 23419 -17668 13732 -107 8299 -14201 17755 -6220 9108 -4640 12402 -2358 18287 -14969 9819 -4614 9826 -2932 21905 -15168 2660 -2985 15059 -16777 21650 -17993 24966 -7943 5452 -1922 18401 -5770 14852 -748 3672 -5821 18493 -10432 19409 -6965 10586 -13130 3445 -4324 18616 -223...

output:

147419094
147419094
147419094
147419094
147419094
147419094
147419094
147419094
147419094
147419094
147419094
147419094
147419094
147419094
147419094
147419094
147419094
147419094
147419094
147419094
147419094
147419094
147419094
147419094
147419094
147419094
147419094
147419094
147419094
147419094
...

result:

ok 25000 numbers

Test #30:

score: 0
Accepted
time: 430ms
memory: 83240kb

input:

25000 25000
-4921 548 -2803 23419 -17668 13732 -107 8299 -14201 17755 -6220 9108 -4640 12402 -2358 18287 -14969 9819 -4614 9826 -2932 21905 -15168 2660 -2985 15059 -16777 21650 -17993 24966 -7943 5452 -1922 18401 -5770 14852 -748 3672 -5821 18493 -10432 19409 -6965 10586 -13130 3445 -4324 18616 -223...

output:

146475654
146264884
146859136
146440437
146586097
146225524
146339644
146203346
145569090
146764887
145948142
145789507
145958603
146174963
146461196
146085269
146179894
147245264
146226931
147175277
146239194
146344487
146057000
146920693
145667283
146190538
145909043
146045890
146432940
146228301
...

result:

ok 25000 numbers

Test #31:

score: 0
Accepted
time: 796ms
memory: 73352kb

input:

25000 35000
-1387 8051 6320 18421 26993 -246 6216 -2791 -151 -3872 31648 12594 -21771 -1625 24312 33472 -33893 27738 3643 -8660 20259 -17938 21819 2792 15497 -3506 -23731 -1213 -25283 33511 20132 -28711 -4452 -32031 2966 -22276 10625 17286 16735 18925 30142 8317 22270 -23773 -6061 32753 30609 -13232...

output:

1518071
686142
4492232
16931294
69332231
-419932
41754699
12009814
47102055
28323603
60033646
42358588
98018476
62808051
56266944
124965691
127249178
116087871
57039390
73483700
36420732
106325817
1606654
141345999
5032100
47360643
19667177
23225665
164954899
89161553
174044060
113206999
6351209
445...

result:

ok 35000 numbers

Test #32:

score: 0
Accepted
time: 797ms
memory: 93048kb

input:

35000 35000
-10896 -1698 -9716 8864 3021 4933 -30624 3545 26541 33880 -30343 4291 -28181 29420 3908 -12082 -19308 22855 18650 -24335 -18501 -7455 -17664 -27295 -30713 -6863 -3693 -20963 12614 -15882 -4141 2211 -17486 12327 -10916 29608 -23810 -10316 -16789 -31364 14697 -12744 -6860 28747 -14851 1090...

output:

11013460
8633252
25976655
9727021
24291273
22348462
13003278
16808219
4502885
1786824
24660105
27830035
25012625
24660387
25421604
12647605
6433058
14178559
16069055
9753656
16819977
4613537
15180889
23206538
10443266
11713025
11019626
9355081
17167321
3134449
7855740
15244460
13078495
15190352
9544...

result:

ok 35000 numbers

Test #33:

score: 0
Accepted
time: 939ms
memory: 105200kb

input:

35000 35000
-21209 5740 -32748 32282 -30755 29900 -2057 30530 -32491 8746 -25186 30625 -25581 10080 -28009 23445 -23438 23576 -21035 31046 -20718 5954 -6263 32613 -12812 30645 -22019 9376 -15498 33636 -13374 29271 -32837 14241 -30711 20841 -33843 19081 -6057 13996 -13011 19818 -12891 28806 -16781 93...

output:

30393806
6290195
198304022
182506055
163184945
121760502
71548185
76920733
64628859
2783243
81346830
83012965
130812915
54615678
73231427
60836908
13554363
56209007
137759042
136022127
174262080
11133752
66416514
204842799
66361741
23282875
40972101
68003766
118669490
4484084
88724923
100475973
1063...

result:

ok 35000 numbers

Test #34:

score: 0
Accepted
time: 131ms
memory: 105196kb

input:

35000 35000
-21209 5740 -32748 32282 -30755 29900 -2057 30530 -32491 8746 -25186 30625 -25581 10080 -28009 23445 -23438 23576 -21035 31046 -20718 5954 -6263 32613 -12812 30645 -22019 9376 -15498 33636 -13374 29271 -32837 14241 -30711 20841 -33843 19081 -6057 13996 -13011 19818 -12891 28806 -16781 93...

output:

286973654
286973654
286973654
286973654
286973654
286973654
286973654
286973654
286973654
286973654
286973654
286973654
286973654
286973654
286973654
286973654
286973654
286973654
286973654
286973654
286973654
286973654
286973654
286973654
286973654
286973654
286973654
286973654
286973654
286973654
...

result:

ok 35000 numbers

Test #35:

score: 0
Accepted
time: 625ms
memory: 106844kb

input:

35000 35000
-21209 5740 -32748 32282 -30755 29900 -2057 30530 -32491 8746 -25186 30625 -25581 10080 -28009 23445 -23438 23576 -21035 31046 -20718 5954 -6263 32613 -12812 30645 -22019 9376 -15498 33636 -13374 29271 -32837 14241 -30711 20841 -33843 19081 -6057 13996 -13011 19818 -12891 28806 -16781 93...

output:

285888183
285147760
285208470
285016899
285913070
284998617
286116645
285560614
285037524
285433718
284690216
285466418
284435248
284402051
285899869
284269371
284960946
285495787
285201184
284441138
284220617
285816298
285429436
284795180
284305334
285476073
283969595
286037144
285640790
285812583
...

result:

ok 35000 numbers

Test #36:

score: 0
Accepted
time: 1017ms
memory: 92316kb

input:

35000 35000
-10896 -1698 -9716 8864 3021 4933 -30624 3545 26541 33880 -30343 4291 -28181 29420 3908 -12082 -19308 22855 18650 -24335 -18501 -7455 -17664 -27295 -30713 -6863 -3693 -20963 12614 -15882 -4141 2211 -17486 12327 -10916 29608 -23810 -10316 -16789 -31364 14697 -12744 -6860 28747 -14851 1090...

output:

10336916
65210086
22631693
183064224
35875264
80457423
71573626
80505772
55169285
1808606
122796977
133899321
143183530
90045772
138737840
60895789
13538383
44105388
133585540
91404378
172367237
22062523
77856561
167954102
39118385
68212224
40407278
14879144
120083679
1543835
49732187
104641794
1057...

result:

ok 35000 numbers

Test #37:

score: 0
Accepted
time: 75ms
memory: 50064kb

input:

35000 35000
-35000 -35000 -35000 -35000 -35000 -35000 -35000 -35000 -35000 -35000 -35000 -35000 -35000 -35000 -35000 -35000 -35000 -35000 -35000 -35000 -35000 -35000 -35000 -35000 -35000 -35000 -35000 -35000 -35000 -35000 -35000 -35000 -35000 -35000 -35000 -35000 -35000 -35000 -35000 -35000 -35000 -...

output:

-35000
-70000
-105000
-140000
-175000
-210000
-245000
-280000
-315000
-350000
-385000
-420000
-455000
-490000
-525000
-560000
-595000
-630000
-665000
-700000
-735000
-770000
-805000
-840000
-875000
-910000
-945000
-980000
-1015000
-1050000
-1085000
-1120000
-1155000
-1190000
-1225000
-1260000
-12950...

result:

ok 35000 numbers

Test #38:

score: 0
Accepted
time: 80ms
memory: 50640kb

input:

35000 35000
35000 35000 35000 35000 35000 35000 35000 35000 35000 35000 35000 35000 35000 35000 35000 35000 35000 35000 35000 35000 35000 35000 35000 35000 35000 35000 35000 35000 35000 35000 35000 35000 35000 35000 35000 35000 35000 35000 35000 35000 35000 35000 35000 35000 35000 35000 35000 35000 ...

output:

1225000000
1225000000
1225000000
1225000000
1225000000
1225000000
1225000000
1225000000
1225000000
1225000000
1225000000
1225000000
1225000000
1225000000
1225000000
1225000000
1225000000
1225000000
1225000000
1225000000
1225000000
1225000000
1225000000
1225000000
1225000000
1225000000
1225000000
122...

result:

ok 35000 numbers