QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#795420#9634. 序列le0n40 2065ms60696kbC++144.8kb2024-11-30 20:21:542024-11-30 20:21:55

Judging History

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

  • [2024-11-30 20:21:55]
  • 评测
  • 测评结果:40
  • 用时:2065ms
  • 内存:60696kb
  • [2024-11-30 20:21:54]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef unsigned long long i128;

class IO {
    char ibuf[1 << 16], obuf[1 << 16], *ipl = ibuf, *ipr = ibuf, *op = obuf;
    public:
    ~IO() { write(); }
    void read() { if (ipl == ipr) ipr = (ipl = ibuf) + fread(ibuf, 1, 1 << 15, stdin); }
    void write() { fwrite(obuf, 1, op - obuf, stdout), op = obuf; }
    char getchar() { return (read(), ipl != ipr) ? *ipl++ : EOF; }
    void putchar(char c) { *op++ = c; if (op - obuf > (1 << 15)) write(); }
    template <typename V> IO& operator >> (V& v) {
        int s = 1; char c = getchar(); v = 0;
        for (; !isdigit(c); c = getchar()) if (c == '-') s = -s;
        for (; isdigit(c); c = getchar()) v = (v << 1) + (v << 3) + (c ^ 48);
        return v *= s, *this;
    }
    IO& operator << (char c) { return putchar(c), *this; }
    template <typename V> IO& operator << (V v) {
        if (!v) putchar('0'); if(v < 0) putchar('-'), v = -v;
        char stk[100], *top = stk;
        for (; v; v /= 10) *++top = v % 10 + '0';
        while (top != stk) putchar(*top--); return *this;
    }
} io;
const int N = 5e5 + 5;
const ll lim = 1e18;
int tam[N << 2], tar[N << 2], mx[N << 2];
ll tag[N << 2], sum[N << 2], sr[N << 2];
i128 ans[N << 2];
int a[N];
void print(i128 x)
{
	io << (ll)x << '\n';
}
void work(int p, int l, int r, int k, int t) // subtree add max(k, premax)
{
	int mid = (l + r) >> 1;
	if(k >= mx[p])
	{
		tag[p] += (ll)k * t;
		ans[p] += (i128)k * t * (r - l + 1);
		return ;
	}
	if(l == r)
	{
		tam[p] += t;
		ans[p] += (i128)t * sum[p];
		return ;
	}
	if(k < mx[p << 1])
	{
		ans[p] -= ans[p << 1];
		work(p << 1, l, mid, k, t);
		tar[p] += t;
		ans[p] += ans[p << 1] + (i128)t * sr[p];
	}
	else
	{
		ans[p] -= ans[p << 1] + ans[p << 1 | 1];
		tag[p << 1] += (ll)k * t;
		ans[p << 1] += (i128)k * t * (mid - l + 1);
		work(p << 1 | 1, mid + 1, r, k, t);
		ans[p] += ans[p << 1] + ans[p << 1 | 1];
	}
	// ans[p] = ans[p << 1] + ans[p << 1 | 1] + (i128)tam[p] * sum[p] + (i128)tar[p] * sr[p] + (i128)tag[p] * (r - l + 1);
}
ll calc(int p, int l, int r, int k)
{
	int mid = (l + r) >> 1;
	if(k >= mx[p])
		return k * (r - l + 1ll);
	if(l == r)
		return sum[p];
	if(k < mx[p << 1])
		return calc(p << 1, l, mid, k) + sr[p];
	else
		return k * (mid - l + 1ll) + calc(p << 1 | 1, mid + 1, r, k);
}
void upd(int p, int l, int r, int q, int k)
{
	int mid = (l + r) >> 1;
	if(l == r)
	{
		tam[p] = 0;
		sum[p] = mx[p] = k;
		return ;
	}
	tam[p << 1] += tam[p];
	ans[p << 1] += (i128)tam[p] * sum[p << 1];
	work(p << 1 | 1, mid + 1, r, mx[p << 1], tam[p] + tar[p]);
	tam[p] = tar[p] = 0;
	if(q <= mid)
		upd(p << 1, l, mid, q, k);
	else
		upd(p << 1 | 1, mid + 1, r, q, k);
	sr[p] = calc(p << 1 | 1, mid + 1, r, mx[p << 1]);
	sum[p] = sum[p << 1] + sr[p];
	mx[p] = max(mx[p << 1], mx[p << 1 | 1]);
	ans[p] = ans[p << 1] + ans[p << 1 | 1] + (i128)tag[p] * (r - l + 1);
}
void build(int p, int l, int r)
{
	int mid = (l + r) >> 1;
	tam[p] = tar[p] = tag[p] = ans[p] = 0;
	if(l == r)
	{
		sum[p] = mx[p] = a[l];
		return ;
	}
	build(p << 1, l, mid);
	build(p << 1 | 1, mid + 1, r);
	sr[p] = calc(p << 1 | 1, mid + 1, r, mx[p << 1]);
	sum[p] = sum[p << 1] + sr[p];
	mx[p] = max(mx[p << 1], mx[p << 1 | 1]);
}
int add(int p, int l, int r, int ql, int qr, int k)
{
	int mid = (l + r) >> 1;
	if(ql <= l && r <= qr)
	{
		work(p, l, r, k, 1);
		return max(mx[p], k);
	}
	int qwq = 0;
	if(qr <= mid)
	{
		ans[p] -= ans[p << 1];
		qwq = add(p << 1, l, mid, ql, qr, k);
		ans[p] += ans[p << 1];
		return qwq;
	}
	if(ql > mid)
	{
		ans[p] -= ans[p << 1 | 1];
		qwq = add(p << 1 | 1, mid + 1, r, ql, qr, k);
		ans[p] += ans[p << 1 | 1];
		return qwq;
	}
	ans[p] -= ans[p << 1] + ans[p << 1 | 1];
	qwq = add(p << 1 | 1, mid + 1, r, ql, qr, add(p << 1, l, mid, ql, qr, k));
	ans[p] += ans[p << 1] + ans[p << 1 | 1];
	return qwq;
}
i128 qry(int p, int l, int r, int ql, int qr)
{
	int mid = (l + r) >> 1;
	if(ql <= l && r <= qr)
		return ans[p];
	int len = min(qr, r) - max(ql, l) + 1;
	tam[p << 1] += tam[p];
	ans[p << 1] += (i128)tam[p] * sum[p << 1];
	work(p << 1 | 1, mid + 1, r, mx[p << 1], tam[p] + tar[p]);
	tam[p] = tar[p] = 0;
	if(qr <= mid)
		return qry(p << 1, l, mid, ql, qr) + (i128)tag[p] * len;
	if(ql > mid)
		return qry(p << 1 | 1, mid + 1, r, ql, qr) + (i128)tag[p] * len;
	return qry(p << 1, l, mid, ql, qr) + qry(p << 1 | 1, mid + 1, r, ql, qr) + (i128)tag[p] * len;
}

int main()
{
	int n, q, i, t, l, r;
	io >> n >> q;
	for(i = 1; i <= n; i++)
		io >> a[i];
	build(1, 1, n);
	while(q--)
	{
		io >> t >> l >> r;
		if(t == 1)
			upd(1, 1, n, l, r);
		if(t == 2)
			add(1, 1, n, l, r, 0);
		if(t == 3)
			print(qry(1, 1, n, l, r));
	}
	return 0;
}

詳細信息

Subtask #1:

score: 5
Accepted

Test #1:

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

input:

1000 1000
200255705 18851142 736009342 406246331 351992319 749189355 944184790 785599293 530084396 616825582 73892135 176401717 973078957 225462579 140426746 324124972 229974996 750749128 879242920 854856469 515750108 662437499 10800517 96488944 534239216 379225718 1241451 150390174 183892560 613018...

output:

115323323048
65823230682
0
47168872319
60782985614
348599053983
918484726470
208925010382
841530027736
1163442457471
2608439690799
2128414546126
2471685184070
2278023608377
4122371223088
1458343349705
62968981524
4425943072510
5286986186209
537921635417
6006016656637
6374912810574
4556755081981
4090...

result:

ok 319 lines

Test #2:

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

input:

675 498
75499042 789966903 502155346 54108007 467143562 114588937 94686746 295185255 554039744 259329427 158379833 138282372 561461541 957169421 692456397 450721274 101897728 872864525 297269606 128259204 146200569 334256573 638122576 708088255 258863311 783805088 186494595 159493286 860425671 36583...

output:

3210556218
191560004083
104947218282
135015954140
89106128730
315174748560
850455290830
215793984626
105038927720
671668276124
293473436208
1370960719682
307802923002
1044297322034
471948015606
1812945110331
509687537766
877665782562
5988747959725
2402086669705
665467763330
3875485682146
30788930819...

result:

ok 157 lines

Test #3:

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

input:

832 956
63423286 492662095 483038836 43381328 710704754 275209586 772971912 639125432 123099101 440862460 183294225 125906357 452957650 331299449 449896214 12572018 605185437 64801748 40959720 490409349 609153090 532014716 503601695 886231182 433385802 11363084 17467752 140921783 203238927 515442553...

output:

159703328433
728165156759
460962189958
139692978146
459083548685
2010218005483
160646809572
1998558719788
2532122916025
208715188685
3433514558392
1245744189229
2304867462814
1101186845031
4646172459091
3539374659926
2219710349880
2981467606232
1639756233272
3123456308009
129830992916
2707661776087
...

result:

ok 298 lines

Test #4:

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

input:

107 458
539936263 550880224 110849701 171862479 40453865 42606847 118258420 901511714 62978713 994457516 790180985 231543035 67333164 220103435 863166805 693458691 735393617 656359198 456294870 483207020 36257117 51902430 86590102 656792972 473981545 132412739 956528165 655526259 389318494 722510414...

output:

37703321582
61151152486
38167350208
27335153157
13391394310
39026827445
9471505258
132653861927
53752862940
55529822900
30680946663
4850841785
63192296538
51576868617
68746826458
72693752015
9960381094
54341149280
153650643409
85423704752
30991460260
76087303259
206268124856
210773791402
16018411054...

result:

ok 147 lines

Test #5:

score: 5
Accepted
time: 3ms
memory: 17984kb

input:

933 247
290494705 534765936 691140472 652599148 796414457 950767936 884921919 736175995 398100604 985864598 604544799 325091836 100139758 78534816 237456204 966229805 77069564 843105831 62870326 241741343 997490857 25434019 587844838 826260504 87495532 783942134 938382330 817416196 861328912 8872012...

output:

527080492570
170522861753
35492358564
1118019649402
1245650784268
517846428173
157238640740
64050364170
1165387164835
797344988879
905518201748
585830293577
1469275121374
2090399342887
993895826760
563204905613
2275566746139
891332495993
510813367529
3220707417878
4014471703279
1232981799608
1788988...

result:

ok 88 lines

Subtask #2:

score: 15
Accepted

Test #6:

score: 15
Accepted
time: 133ms
memory: 28664kb

input:

100000 100000
4637 12023 22485 24887 33065 35780 37538 49402 71281 72891 82706 82752 91276 108256 240372831 135259 144119 527163065 139510686 183411 214260 269767144 246850 265137 200716505 279533 283217 309516 310867 466875375 322790 328304 352577 362081 368658 370430 393854 410075 413844 417924 42...

output:

0
30726293751614
23279151095632
41852587040702
88334302224542
55145178872681
133708315362378
122479400900129
51466277782595
118512887868405
11037534475440
65035924904178
10603452209550
199208093593954
265893836606312
214479670680947
204140164589562
309440794035363
371664753856955
431192829952188
223...

result:

ok 33171 lines

Test #7:

score: 15
Accepted
time: 134ms
memory: 26568kb

input:

100000 100000
19723 39392 45074 51502 53631 57384 62795 83715 87504 89050 841832193 866044146 107373 108026 345025215 112030 116974 122686 123235 148805 149471 956007390 165128 786395423 169262 171279 178785 179135 179363 180975 182200 187213 212008 217112 218394 221491 233714 819427472 238361 24227...

output:

0
32124614467875
69730586575982
15351815760648
39463147851339
16268178614557
303342370917063
346244985109518
292833305376516
352153160757784
158244261040178
599241224673877
67404589393329
432694296417372
124742290707994
314297538152335
495171088283939
417004525148234
143916527742938
338939254812923
...

result:

ok 33331 lines

Test #8:

score: 15
Accepted
time: 117ms
memory: 30720kb

input:

100000 100000
2908 10473 29474 35649 40424 46783 50041 68445 81098 96582 90025 102538 128766 120910 131449 149397 169408 167938 187128 192288 196084 207953 217258 231306 247570 248623 250548 266615 274685 296144 299431 306652 323405 326332 341744 340727 363155 376283 381987 389450 398454 406178 4118...

output:

377915538139549
79386636621796
310648735973954
1115465766317781
1174759112421105
1267214610548620
144309126675820
791491017938869
790485778190958
1992438100036954
3728927904532942
3450408776333060
1148459259855542
3434668196031763
1429031077622813
4384069058754410
4712920036420316
1905079428498382
1...

result:

ok 4980 lines

Test #9:

score: 15
Accepted
time: 201ms
memory: 32828kb

input:

100000 100000
1 5416 10193 20973 43641 59111 59710 61214 83161 89367 92875 103278 120697 123362 132339 144415 150301 177312 177726 186305 198765 215887 229844 225598 243960 243968 253899 264297 270663 295463 297815 313600 322370 325050 339675 343618 366146 371128 372853 399869 392890 416762 427071 4...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
12506289774675
30993852542994
1476270298068
19859163976805
256593130788
4863792552078
36510986090424
0
8793244932194
0
27496507734929
46196387428852
10116507432109
39651727981238
9881579282058
47734322666145
9721472071510
13783772572906
49612189104874
34561802750647
709...

result:

ok 90082 lines

Test #10:

score: 15
Accepted
time: 154ms
memory: 28672kb

input:

100000 100000
1 19147 10463 34611 35980 52756 56153 69683 88615 99259 98503 116764 125535 124685 147668 148442 165440 179502 177942 189770 192749 210988 225546 239486 239605 256115 254808 277994 280096 281446 304064 310129 314591 338439 341802 353959 354678 367015 375732 388669 401837 415599 425050 ...

output:

0
0
4895336576636
24273351987479
0
29184129318917
6733439631000
0
22091734242466
0
30621121378918
9663021894490
10825012438813
16599195369255
18919747078225
70174059707617
106918147267604
162528871022197
91971637270994
110828263125883
184744551106766
39546233888866
135239194093210
136071671449847
18...

result:

ok 4885 lines

Subtask #3:

score: 20
Accepted

Test #11:

score: 20
Accepted
time: 336ms
memory: 39248kb

input:

199996 199998
5015 394604305 13416 39971157 16609 21608 24264 407389425 31670 31976 33151 38949 39093 43561 45026 52355 53865 59168 62183 64166 66110 67179 69567 78899 10409535 393971884 104797 109461 109501 114704 118658 123559 123907 130465 131312 140968 144801 146183 157067 160370 796894425 17818...

output:

124830885330445
163133190457804
21829962212270
97332810213576
143489565142015
101516391700168
11850432340486
170205236804236
447031192227296
157109166149152
992595580711424
2459784243144
90627247023452
229326680354895
929560394107059
338204574812304
609780011775761
527358703064443
385256587900185
16...

result:

ok 66818 lines

Test #12:

score: 20
Accepted
time: 479ms
memory: 39120kb

input:

199998 199999
168 3359 6105 15486 21875 25864 26468 30351 43952 43989 53793 53923 61996 63968 65630 70205 78972 81963 94601 94496 96858 109506 114092 118673 120001 125356 130839 134104 143348 141897 151011 153528 157134 164610 167357 171010 177495 186843 193531 193638 201233 202713 208183 212666 223...

output:

0
4378051270375
0
6903808423403
13362901828733
18444776076770
24372543933372
158384277197471
6735580542339
25778920050816
111413592672333
200397968479242
143113451226432
205402754231468
0
434973423866394
42704336802074
442387964318825
171170830546889
18443266342726
582023884944817
819893988905193
94...

result:

ok 66333 lines

Test #13:

score: 20
Accepted
time: 463ms
memory: 39244kb

input:

199996 199998
1 8536 12954 19783 24275 23112 27131 34314 36101 42615 48466 55598 62138 62041 66894 76298 80786 83532 94549 95266 99934 103499 106876 115843 124352 125509 131309 133329 142222 147539 148560 151511 159600 163448 171677 174052 178953 184230 188029 193110 199225 203957 211003 214530 2173...

output:

0
0
0
0
14230186293404
15014710688740
69339379467107
157959280933497
124274051765400
86841342219535
125440741040951
374686462687449
1769370913820
224600387765048
108156479666221
3476736401531
4338871624824
29506026393352
358909490712855
246444614376890
159607092663372
143268992784813
674698942075974...

result:

ok 10049 lines

Test #14:

score: 20
Accepted
time: 370ms
memory: 39112kb

input:

199999 199997
1 4065 13359 10483 20784 20157 25556 39760 41476 45884 52871 54407 55577 65959 69590 74858 81749 86436 91329 98879 97009 105999 113477 117069 116743 122114 126146 134968 141127 149818 150629 157016 159290 169139 168704 174398 182101 189350 188710 190054 195317 202111 208298 213463 2184...

output:

356664773280160
271576584537205
327103957637028
2437225740748747
424187891897923
3136989129319026
1823818488324464
2616111643348778
1096269625861496
101009675213988
4940972090515486
6514435670175637
7612523705881197
2639797844667310
4384189184591598
962636216165669
4693306475088573
9631726489351068
...

result:

ok 9919 lines

Test #15:

score: 20
Accepted
time: 646ms
memory: 39256kb

input:

199998 199996
1 487 6502 19580 16435 25298 31247 31018 40108 40947 54517 56109 57587 66623 72598 78065 75147 80358 87866 91253 103921 106603 112657 119454 115153 123264 126135 139643 142286 146464 148647 158426 160574 167320 167984 172186 184199 182075 188571 196590 201899 204304 210013 217785 21714...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
52089694319421
5136957493076
3450951990644
61850716056488
31244298493786
21509654027244
80848058425062
38845223723325
84427687790134
42434414680971
78744664386759
44358604063388
59495332272505
93887268574436
11926208216313
8042283208270
84995354850496
65164553742256
138...

result:

ok 179917 lines

Subtask #4:

score: 0
Wrong Answer

Test #16:

score: 20
Accepted
time: 2065ms
memory: 59624kb

input:

499996 499997
1 2646 3802 4717 7652 9462 10048 15736 15959 17076 21684 21628 25147 26990 26023 28835 33604 34213 36006 39643 38238 40133 45193 44699 47403 48437 51742 53992 57055 56322 61353 61812 62008 67837 66136 70512 72503 72294 75169 77534 81608 80173 85831 85776 87518 89661 93233 93800 96640 9...

output:

0
0
0
0
0
105147493356021
18039314547119
60123011205734
797041402206
80680889110877
0
97607273260486
71194267494796
23670063883525
92041637115786
11373629471803
104829243846562
112256838369147
16646163554581
83634910857933
110480671764271
2174900945295
97605316257427
25997394270292
1924389041448
137...

result:

ok 450128 lines

Test #17:

score: 0
Wrong Answer
time: 729ms
memory: 60696kb

input:

499998 499996
1 3471 2549 4182 8919 10258 11561 15179 16303 17220 20893 23445 24991 27357 26370 28731 30556 35428 37486 37835 39061 43719 43122 44729 48319 51703 50012 52147 57593 57437 61479 63875 64817 67167 67191 69596 70253 73553 76856 76030 78391 83022 82701 87998 88253 90359 92016 93464 96464 ...

output:

1293275144175713
2098057486611995
8222351022350847
17610615352954277
6318371993395498
13728539476460850
6533073631723592
14700814893017093
21018382511562240
5631782124013074
6045739759458044
32012453560709915
4647695248557350
33891352492409939
25680366630303673
30384715040873579
21745305855945815
23...

result:

wrong answer 4398th lines differ - expected: '9279427647422327013', found: '-9167316426287224603'

Subtask #5:

score: 0
Wrong Answer

Test #19:

score: 0
Wrong Answer
time: 1203ms
memory: 59580kb

input:

499999 499997
1 913 5858 7110 8076 9893 13142 12135 14769 16455 20711 22647 22330 25867 26677 28695 32280 33608 34824 39255 40515 43887 42090 46155 49082 48316 50861 55535 54485 56506 59203 61928 62076 66600 68030 69805 72680 74796 75455 79690 78235 83297 82398 85367 87069 89711 93646 92554 95923 97...

output:

103621325428465
194930859933753
353758078534853
1405031453939581
1104512586294893
480139615473767
1033865068621131
1418492876310288
1129269195811974
845644688375455
3918331221480338
4521399133967034
482692294649644
1270881159480750
2064526258912334
7779855812924988
5610050149593744
1191164601160151
...

result:

wrong answer 12671st lines differ - expected: '9252676369918254289', found: '-9194067703791297327'

Subtask #6:

score: 0
Wrong Answer

Test #23:

score: 0
Wrong Answer
time: 1619ms
memory: 59056kb

input:

500000 499997
811 680 2664 6777 6210 8794 10852 13568 17252 18119 19538 22423 23434 24510 27591 29645 31329 33806 37129 37447 40339 41361 45606 47813 47448 50532 50029 53543 54938 56738 59038 63199 62439 67323 68737 71432 71039 75469 76122 79648 80334 81276 84567 85506 89609 91503 91445 94036 97338 ...

output:

0
0
46530827437710
159760134281336
281467808921043
372576789411254
270515121922085
273418740230876
314163853033674
465151417299684
39902282964668
608644183868574
3945842783692
13545278446404
658747128786432
8688035320113
175738882065799
103795597112962
0
751662464688101
182137815371386
3400806326455...

result:

wrong answer 111431st lines differ - expected: '9261750822065135130', found: '-9184993251644416486'