QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#290628#2011. 划分MoRanSky100 ✓720ms769688kbC++231.9kb2023-12-25 06:11:252023-12-25 06:11:25

Judging History

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

  • [2023-12-25 06:11:25]
  • 评测
  • 测评结果:100
  • 用时:720ms
  • 内存:769688kb
  • [2023-12-25 06:11:25]
  • 提交

answer

#include <cstdio>
#include <iostream>
#define d(x) (s[x] - s[pre[x]])
using namespace std;
typedef long long LL;
typedef long double LD;
const int N = 40000001, M = 100001, MOD = 1 << 30;
const LL BASE = 1e17;
int n, type, q[N], pre[N];
int m, b[N], p[M], l[M], r[M];
LL s[N];
struct HP{
    LL x, y;
    HP(int num = 0)  {
        x = 0, y = num;
    }
    // num = x * BASE + y
    HP inline operator + (const HP b) const {
        HP c; 
        c.x = x + b.x, c.y = y + b.y;
        c.x += c.y / BASE, c.y %= BASE;
        return c;
    }
    void inline print() {
        if(x) printf("%lld%017lld\n", x, y);
        else printf("%lld\n", y);
    }
};
HP inline mul (const LL a, const LL b) {
    HP c;
    c.x = (LD)a * b / BASE;
    c.y = ((a * b - c.x * BASE) % BASE + BASE) % BASE;
    return c;
}

void inline read(int &x) {
	x = 0; char s = getchar();
	while(s > '9' || s < '0') s = getchar();
	while(s <= '9' && s >= '0') x = x * 10 + s - '0', s = getchar();
}
int main() {
	read(n); read(type);
	if(type) {
		int x, y, z; 
		read(x); read(y); read(z); read(b[1]); read(b[2]); read(m);
		for (register int i = 1; i <= m; i++) read(p[i]), read(l[i]), read(r[i]);
		for (register int i = 3; i <= n; i++) b[i] = ((LL)x * b[i - 1] + (LL)y * b[i - 2] + z) % MOD;
		for (register int i = 1; i <= m; i++)
			for (int j = p[i - 1] + 1; j <= p[i]; j++) s[j] = s[j - 1] + (b[j] % (r[i] - l[i] + 1)) + l[i];
	} else for (int i = 1, x; i <= n; i++) read(x), s[i] = s[i - 1] + x;
	int hh = 0, tt = 0;
	for (register int i = 1; i <= n; i++) {
		while(hh < tt && d(q[hh + 1]) + s[q[hh + 1]] <= s[i]) hh++;
		pre[i] = q[hh];
		while(hh <= tt && d(q[tt]) + s[q[tt]] >= d(i) + s[i]) tt--;
		q[++tt] = i;
	}
	HP ans = HP();
	for (register int i = n; i; i = pre[i]) ans = ans + mul(s[i] - s[pre[i]], s[i] - s[pre[i]]);
	ans.print();
	return 0;
}

詳細信息

Test #1:

score: 4
Accepted
time: 1ms
memory: 5836kb

input:

1 0
1

output:

1

result:

ok answer is '1'

Test #2:

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

input:

10 0
5 1 2 1 1 1 1 1 2 3

output:

108

result:

ok answer is '108'

Test #3:

score: 4
Accepted
time: 1ms
memory: 5784kb

input:

10 0
5 1 1 4 3 2 1 6 5 6

output:

254

result:

ok answer is '254'

Test #4:

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

input:

50 0
488 19 20 6 7 8 9 10 11 171 172 173 174 64 64 64 64 64 64 64 64 64 64 64 64 218 219 220 221 222 223 224 225 226 101 102 103 104 105 224 225 226 227 37 38 39 40 41 42 43

output:

4485725

result:

ok answer is '4485725'

Test #5:

score: 4
Accepted
time: 1ms
memory: 5772kb

input:

50 0
657 83 80 81 86 60 84 85 63 64 61 335 13 14 6 7 6 7 6 7 6 7 6 17 17 17 17 17 135 136 130 131 108 109 134 135 112 113 138 139 90 91 94 95 94 95 98 99 98 99

output:

3963358

result:

ok answer is '3963358'

Test #6:

score: 4
Accepted
time: 1ms
memory: 5820kb

input:

50 0
538 3 4 3 4 3 4 3 128 89 90 131 72 79 76 71 84 81 82 73 76 83 74 83 82 71 72 71 74 81 8 3 2 13 14 5 8 1 1 1 1 151 152 169 168 113 118 175 316 618

output:

3376710

result:

ok answer is '3376710'

Test #7:

score: 4
Accepted
time: 1ms
memory: 5836kb

input:

400 0
3009 356 438 551 606 387 2073 2777 2778 824 404 394 554 248 545 261 262 548 253 561 403 415 279 543 544 131 148 101 142 111 96 161 162 99 116 3890 204 181 166 223 224 169 186 211 180 221 206 3467 3468 2517 2253 2214 2247 2224 2209 2266 2267 2212 2229 2254 765 449 469 749 750 472 454 772 735 49...

output:

3170248737

result:

ok answer is '3170248737'

Test #8:

score: 4
Accepted
time: 1ms
memory: 5900kb

input:

400 0
5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673...

output:

6979363199

result:

ok answer is '6979363199'

Test #9:

score: 4
Accepted
time: 1ms
memory: 5772kb

input:

400 0
3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484...

output:

3318244868

result:

ok answer is '3318244868'

Test #10:

score: 4
Accepted
time: 1ms
memory: 5820kb

input:

5000 0
26416 26417 26418 26419 26420 26421 26422 26423 26424 26425 26426 26427 26428 26429 26430 26431 26432 26433 26434 26435 26436 26437 26438 26439 26440 26441 26442 26443 26444 26445 26446 26447 26448 26449 26450 26451 26452 26453 26454 26455 26456 26457 26458 26459 26460 26461 26462 26463 26464...

output:

33887118980393

result:

ok answer is '33887118980393'

Test #11:

score: 4
Accepted
time: 1ms
memory: 5828kb

input:

5000 0
23207 23208 23209 23210 23211 23212 23213 23214 23215 23216 23217 23218 23219 23220 23221 23222 23223 23224 23225 23226 23227 23228 23229 23230 23231 23232 23233 23234 23235 23236 23237 23238 23239 23240 23241 23242 23243 23244 23245 23246 23247 23248 23249 23250 23251 23252 23253 23254 23255...

output:

33248894141865

result:

ok answer is '33248894141865'

Test #12:

score: 4
Accepted
time: 1ms
memory: 5812kb

input:

5000 0
66757 66758 66759 66760 66761 66762 66763 66764 66765 66766 66767 66768 66769 66770 66771 66772 66773 66774 66775 66776 66777 66778 66779 66780 66781 66782 66783 66784 66785 66786 66787 66788 66789 66790 66791 66792 66793 66794 66795 66796 66797 66798 66799 66800 66801 66802 66803 66804 66805...

output:

37723392435267

result:

ok answer is '37723392435267'

Test #13:

score: 4
Accepted
time: 1ms
memory: 5900kb

input:

5000 0
27900 27901 27902 27903 27904 27905 27906 27907 27908 27909 27910 27911 27912 27913 27914 27915 27916 27917 27918 27919 27920 27921 27922 27923 27924 27925 27926 27927 27928 27929 27930 27931 27932 27933 27934 27935 27936 27937 27938 27939 27940 27941 27942 27943 27944 27945 27946 27947 27948...

output:

32475835026360

result:

ok answer is '32475835026360'

Test #14:

score: 4
Accepted
time: 1ms
memory: 5832kb

input:

5000 0
88538 88539 88540 88541 88542 88543 88544 88545 88546 88547 88548 88549 88550 88551 88552 88553 88554 88555 88556 88557 88558 88559 88560 88561 88562 88563 88564 88565 88566 88567 88568 88569 88570 88571 88572 88573 88574 88575 88576 88577 88578 88579 88580 88581 88582 88583 88584 88585 88586...

output:

46614887221321

result:

ok answer is '46614887221321'

Test #15:

score: 4
Accepted
time: 1ms
memory: 5836kb

input:

5000 0
57597 57598 57599 57600 57601 57602 57603 57604 57605 57606 57607 57608 57609 57610 57611 57612 57613 57614 57615 57616 57617 57618 57619 57620 57621 57622 57623 57624 57625 57626 57627 57628 57629 57630 57631 57632 57633 57634 57635 57636 57637 57638 57639 57640 57641 57642 57643 57644 57645...

output:

42148252068110

result:

ok answer is '42148252068110'

Test #16:

score: 4
Accepted
time: 1ms
memory: 5884kb

input:

5000 0
32091 32092 32093 32094 32095 32096 32097 32098 32099 32100 32101 32102 32103 32104 32105 32106 32107 32108 32109 32110 32111 32112 32113 32114 32115 32116 32117 32118 32119 32120 32121 32122 32123 32124 32125 32126 32127 32128 32129 32130 32131 32132 32133 32134 32135 32136 32137 32138 32139...

output:

36356787333837

result:

ok answer is '36356787333837'

Test #17:

score: 4
Accepted
time: 14ms
memory: 14312kb

input:

500000 0
232520 232521 232522 232523 232524 232525 232526 232527 232528 232529 232530 232531 232532 232533 232534 232535 232536 232537 232538 232539 232540 232541 232542 232543 232544 232545 232546 232547 232548 232549 232550 232551 232552 232553 232554 232555 232556 232557 232558 232559 232560 2325...

output:

3404048031740228391

result:

ok answer is '3404048031740228391'

Test #18:

score: 4
Accepted
time: 9ms
memory: 16324kb

input:

500000 0
171097 171098 171099 171100 171101 171102 171103 171104 171105 171106 171107 171108 171109 171110 171111 171112 171113 171114 171115 171116 171117 171118 171119 171120 171121 171122 171123 171124 171125 171126 171127 171128 171129 171130 171131 171132 171133 171134 171135 171136 171137 1711...

output:

3274086928325086647

result:

ok answer is '3274086928325086647'

Test #19:

score: 4
Accepted
time: 8ms
memory: 14908kb

input:

500000 0
507482 507483 507484 507485 507486 507487 507488 507489 507490 507491 507492 507493 507494 507495 507496 507497 507498 507499 507500 507501 507502 507503 507504 507505 507506 507507 507508 507509 507510 507511 507512 507513 507514 507515 507516 507517 507518 507519 507520 507521 507522 5075...

output:

3313623507696416665

result:

ok answer is '3313623507696416665'

Test #20:

score: 4
Accepted
time: 7ms
memory: 14200kb

input:

500000 0
184967 184968 184969 184970 184971 184972 184973 184974 184975 184976 184977 184978 184979 184980 184981 184982 184983 184984 184985 184986 184987 184988 184989 184990 184991 184992 184993 184994 184995 184996 184997 184998 184999 185000 185001 185002 185003 185004 185005 185006 185007 1850...

output:

3136834726987393666

result:

ok answer is '3136834726987393666'

Test #21:

score: 4
Accepted
time: 6ms
memory: 16688kb

input:

500000 0
532977 532978 532979 532980 532981 532982 532983 532984 532985 532986 532987 532988 532989 532990 532991 532992 532993 532994 532995 532996 532997 532998 532999 533000 533001 533002 533003 533004 533005 533006 533007 533008 533009 533010 533011 533012 533013 533014 533015 533016 533017 5330...

output:

3194381893489801230

result:

ok answer is '3194381893489801230'

Test #22:

score: 4
Accepted
time: 9ms
memory: 14808kb

input:

500000 0
599257 599258 599259 599260 599261 599262 599263 599264 599265 599266 599267 599268 599269 599270 599271 599272 599273 599274 599275 599276 599277 599278 599279 599280 599281 599282 599283 599284 599285 599286 599287 599288 599289 599290 599291 599292 599293 599294 599295 599296 599297 5992...

output:

3354933513897756362

result:

ok answer is '3354933513897756362'

Test #23:

score: 4
Accepted
time: 674ms
memory: 734944kb

input:

40000000 1
825772993 851948608 851948609 23077817 23077818 100000
10000000 446359966 479914397
10000183 7872606 12920943
10000224 18747237 34932367
10000774 715284 1347398
10000783 4500773 5923057
10000848 7595142 12326977
10001084 1751295 2861166
10001125 28884730 66396069
10001224 1665580 4330825
...

output:

3794994452005049854674339

result:

ok answer is '3794994452005049854674339'

Test #24:

score: 4
Accepted
time: 653ms
memory: 750968kb

input:

40000000 1
843670282 1068932343 1068932344 12005507 12005508 100000
20000000 191508704 225063135
20000141 4584807 5416311
20000145 65746435 112259590
20000167 4346564 21967365
20000417 2266330 3876735
20000603 1300349 1420996
20000627 57332003 76865807
20000815 5508102 7166761
20000829 1099459 12066...

output:

2875588265896779695426252

result:

ok answer is '2875588265896779695426252'

Test #25:

score: 4
Accepted
time: 720ms
memory: 769688kb

input:

40000000 1
308437383 27106938 27106939 1520476 1520477 100000
30000000 7283395 40837826
30000152 20261079 22140420
30000179 11499826 17155751
30000263 2862681 14509444
30000304 26080900 28618133
30000307 392145002 594277322
30000310 40914057 209553353
30000321 4973733 11165065
30000463 7186086 79328...

output:

2049762805232475409502206

result:

ok answer is '2049762805232475409502206'