QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#384618 | #2982. 链上二次求和 | Ecec243 | 100 ✓ | 801ms | 17656kb | C++23 | 2.5kb | 2024-04-10 06:50:01 | 2024-04-10 06:50:02 |
Judging History
answer
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long LL;
const int N = 200005, P = 1e9 + 7;
int n, m, Div2, s[N], A[N], B[N];
int v[N << 2], sum[N << 2], sa[N << 2], sb[N << 2], sc[N << 2];
int inline power(int a, int b) {
int res = 1;
while (b) {
if (b & 1) res = (LL)res * a % P;
a = (LL)a * a % P;
b >>= 1;
}
return res;
}
int inline calc(int l, int r, int a, int b, int c) {
int x2 = ((LL)A[r] - A[l - 1] + P) % P, x1 = ((LL)B[r] - B[l - 1] + P) % P, x0 = r - l + 1;
return ((LL)x2 * a + (LL)x1 * b + (LL)x0 * c) % P;
}
void inline pushup(int p) {
sum[p] = ((LL)v[p] + sum[p << 1] + sum[p << 1 | 1]) % P;
}
void inline change(int p, int l, int r, int x, int y, int a, int b, int c) {
if (l > r) return;
if (x <= l && r <= y) {
(sa[p] += a) %= P, (sb[p] += b) %= P, (sc[p] += c) %= P;
(v[p] += calc(l, r, a, b, c)) %= P;
(sum[p] += calc(l, r, a, b, c)) %= P;
return;
}
int mid = (l + r) >> 1;
if (x <= mid) change(p << 1, l, mid, x, y, a, b, c);
if (mid < y) change(p << 1 | 1, mid + 1, r, x, y, a, b, c);
pushup(p);
}
int inline query(int p, int l, int r, int x, int y) {
if (x <= l && r <= y) return sum[p];
int mid = (l + r) >> 1, res = calc(max(x, l), min(y, r), sa[p], sb[p], sc[p]);
if (x <= mid) (res += query(p << 1, l, mid, x, y)) %= P;
if (mid < y) (res += query(p << 1 | 1, mid + 1, r, x, y)) %= P;
return res;
}
int inline ask(int l, int r) {
if (l == 0 && r == 0) return 0;
if (l == 0) l++;
return ((LL)s[r] - s[l - 1] + P + query(1, 1, n, l, r)) % P;
}
int main() {
Div2 = power(2, P - 2);
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%d", s + i);
s[i] = (s[i - 1] + s[i]) % P;
A[i] = (A[i - 1] + (LL)i * i) % P;
B[i] = (B[i - 1] + i) % P;
}
for (int i = 1; i <= n; i++)
(s[i] += s[i - 1]) %= P;
for (int i = 1; i <= n; i++)
(s[i] += s[i - 1]) %= P;
while (m--) {
int opt, l, r; scanf("%d%d%d", &opt, &l, &r);
if (l > r) swap(l, r);
if (opt == 1) {
int d; scanf("%d", &d);
change(1, 1, n, l, r, (LL)d * Div2 % P, (LL)d * (3 - 2ll * l + P) % P * Div2 % P, (LL)d * ((2 + (LL)l * (l - 3 + P)) % P) % P * Div2 % P);
int k = (LL)d * (r - l + 1) % P, u = (LL)d * (r - l + 2) % P * (r - l + 1) % P * Div2 % P;
change(1, 1, n, r + 1, n, 0, k, (P - (LL)r * k % P + u) % P);
} else {
printf("%lld\n", ((LL)ask(n, n) * (r - l + 1) - ask(l - 1, r - 1) - ask(n - r, n - l) + 2 * P) % P);
}
}
return 0;
}
详细
Test #1:
score: 5
Accepted
time: 1ms
memory: 5856kb
input:
50 50 606758505 207084089 693903190 124655894 312123617 372945375 51577122 592774230 788262811 233111008 586316912 811155757 613548406 558231835 538440212 408593112 12961928 25115463 751758964 671890342 442470041 69550445 399094754 338869625 13326756 209528425 989614372 115681865 861249626 19159399 ...
output:
121698986 78892206 619084317 451980650 380068157 693975725 433391121 364776043 772949710 347261364 581961306 135474788 81866368 588997409 477392574 209332811 868232822 229196764 84650502 656315715 966960116 150700460 661333301 665799528 786562500
result:
ok 25 lines
Test #2:
score: 5
Accepted
time: 1ms
memory: 5840kb
input:
49 50 645467107 791737958 63304044 277232342 823263784 574925194 38299198 573610425 414154069 158666537 328412661 120695540 53534893 639637900 564497432 392274429 67984958 13332587 767428444 704202235 664379781 47093126 730945541 80991819 138081194 66286844 170222186 330252028 330528839 800748527 15...
output:
564204519 960839106 90051162 274060655 706160651 216203645 438768931 694685197 565221543 99462601 715786601 150481169 652153956 628164625 42028231 114062315 553638573 737608614 497721417 912709672 865157185 651550454 516877686 70157723 419058696 321632203 721558533
result:
ok 27 lines
Test #3:
score: 5
Accepted
time: 1ms
memory: 3936kb
input:
300 300 216591192 625540070 768278380 414601295 911713636 326950793 45239056 945902028 874510111 193218588 798082362 701620171 879692272 830771007 795329399 903233526 386362835 935643590 986806337 40102243 712649174 99474490 61304669 668922682 829267101 676061014 65065595 273251564 802663647 1182158...
output:
782549427 498726016 801986255 784255909 540017045 197878250 688187846 301097862 511780211 878400518 241276776 564954143 829562412 455775020 751468601 945538428 803620991 640306444 33239513 328802710 973268408 805252001 450885335 331611390 910171645 149303935 553956168 807649650 377637093 794648400 3...
result:
ok 150 lines
Test #4:
score: 5
Accepted
time: 1ms
memory: 3944kb
input:
300 299 21784166 385160404 466659210 956930591 601511864 70193077 82043656 908484056 502249911 340480568 304082002 208373630 197814557 917126057 397945014 371411932 578588150 286831456 32636184 372833259 349040157 151683875 576913006 796440926 74761668 980925868 87355973 601062167 995880944 99137412...
output:
654697192 977544572 759281770 679800837 970972206 656786328 132678294 144385857 330658105 490446198 826967619 235455428 571117143 112343044 246098931 337643733 845544771 60842938 817362518 654607345 302717559 77064225 67484183 584484334 765851305 397531091 720378152 991954852 266440264 98959148 7152...
result:
ok 196 lines
Test #5:
score: 5
Accepted
time: 5ms
memory: 6244kb
input:
5000 5000 294237181 617537812 514653564 599322341 496850456 923628468 299701274 476496809 880072096 404904815 137189184 996445171 535535086 759698281 19527712 824493969 747641392 66794808 917625345 184375553 987909605 758764901 305484478 308627961 412302692 549761007 704068423 875978720 566699606 67...
output:
694135091 442088471 185050028 30586677 947063965 582017124 942538344 585031927 485642904 546927803 62807574 367788503 892235727 705161958 243931098 929489826 711103328 54413566 513061628 738512146 170631508 418836432 696668819 657077761 196775176 12123573 662721812 14524558 877490715 968591420 82675...
result:
ok 2655 lines
Test #6:
score: 5
Accepted
time: 411ms
memory: 6168kb
input:
5000 500000 993821792 896102395 504952043 279759915 801783087 289826521 402454771 517089959 306535821 555162177 279591591 115242817 156072003 283988048 691516925 723630734 105017232 34598958 169822876 6397561 814084519 977622194 310091873 924022460 415057196 486709406 256531419 748558699 873358778 3...
output:
504325002 43118752 712000244 676364699 299942482 840822307 713438306 10516671 441395912 219590748 338225097 356939925 478838393 92857397 878761499 689199685 470271622 48817960 339567174 218221277 893011493 234985969 398311126 877084603 284283162 536765289 634850620 110246469 284964060 95111193 55337...
result:
ok 495000 lines
Test #7:
score: 5
Accepted
time: 415ms
memory: 6192kb
input:
4999 500000 62288637 944621506 800872773 266472579 417315604 550952200 12640465 751714249 402901101 130442792 63764452 233748821 645461379 228961903 63217925 797877740 525855299 114252346 180646058 325624230 515561615 548439934 860838728 166428786 352159934 252165696 255154216 58123921 570406425 192...
output:
358008345 108715780 152912528 590348084 286662009 818734586 856269239 910021303 152216141 711144743 764152027 534752659 384403915 337171814 228492201 439085384 394841037 912049293 834085858 565741670 52288288 442115447 772897019 955923260 895066503 959178001 219380110 621071366 148185549 349738534 4...
result:
ok 495000 lines
Test #8:
score: 5
Accepted
time: 396ms
memory: 6140kb
input:
5000 500000 657965347 381577348 124964422 115627714 302172057 930637349 121907782 230961347 694301083 609886716 655337137 463364936 6607691 896632371 265657344 905613221 21824925 596658279 560507333 532838115 248471258 864478763 934123297 142663229 760232736 694874502 937132875 60998564 875042016 64...
output:
541259074 407148108 540515766 225590358 85462540 673918232 269142549 935406527 45633708 102254530 197037093 488526152 620958122 18465677 162428496 86385066 296295590 561334139 151619468 880257485 715295000 340353008 428719484 953174895 393792620 960389046 998038953 864761720 623906501 581887449 5800...
result:
ok 400000 lines
Test #9:
score: 5
Accepted
time: 16ms
memory: 6620kb
input:
200000 1 793092897 315074341 767088727 45776669 82465414 118417856 51138604 235188070 28447514 797601605 956358863 508086586 487751333 197940423 157978319 969967960 674145477 313097162 500895466 46863661 59119972 762816201 987485290 914816864 36769628 995091891 415673263 884251719 387771568 47473111...
output:
658754882
result:
ok single line: '658754882'
Test #10:
score: 5
Accepted
time: 655ms
memory: 6352kb
input:
200000 500000 8624646 203026971 195346049 455291292 728540120 531888901 230589836 710094963 393737792 391484992 479780542 408185384 93384251 331773354 792021 79503281 377764217 616350068 618620832 162972315 172120797 35864739 200903224 423347587 119275264 223662480 699518407 576240798 688103598 4425...
output:
124655212 869310784 127714423 271414157 961981715 82892496 800764172 632905313 993889352 105049159 95548799 916402215 771324772 609564155 645909499 571028635 710437322 761280411 983106102 604764352 152075796 874675141 304419792 119684462 822647154 371516825 96744249 432190850 222965978 497333428 345...
result:
ok 500000 lines
Test #11:
score: 5
Accepted
time: 647ms
memory: 16456kb
input:
200000 500000 819676794 89786596 53861255 145176089 42168642 391907396 507721982 302480614 419097326 425906541 869109898 650264758 439995956 630897103 401469468 674165761 46644833 827589646 585915513 761583287 50378706 339752065 847628729 243151545 609300604 397555126 858252235 936962142 913770596 2...
output:
152103363 841504546 344302539 54541414 673731115 570088259 23995517 947768421 295555514 369189051 419279892 889917448 566956955 547061982 583773118 60144376 664484228 37042058 384066762 596684854 379305878 12461658 347384940 475909100 106459829 806370167 904478013 804826540 554897175 68350290 368641...
result:
ok 400000 lines
Test #12:
score: 5
Accepted
time: 423ms
memory: 16644kb
input:
200000 500000 157328106 665301875 94402206 250767068 258183423 445398651 666708601 932995257 622238810 812871163 694152152 604505034 626296406 865205042 48960227 272492135 819690756 856658351 692526259 685083515 763961255 11283920 286955478 674902789 228610873 469960549 974184655 5157010 520316644 6...
output:
49617383 49617383 49617383 49617383 216593754 216593754 216593754 216593754 216593754 127696037 127696037 127696037 127696037 127696037 504698284 537160877 537160877 537160877 490064994 490064994 490064994 490064994 490064994 2535130 2535130 827499023 827499023 827499023 827499023 827499023 82749902...
result:
ok 400000 lines
Test #13:
score: 5
Accepted
time: 546ms
memory: 6224kb
input:
200000 500000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
output:
0 0 0 502056346 928880781 309549501 6472167 880749669 620331642 401002641 185729209 891553232 804142415 763802738 756943275 754306929 494175446 140423235 703873878 896316410 239608231 213155250 494594551 681281575 169868773 89881150 450768801 431651665 139305048 904878615 209120902 809503581 6486006...
result:
ok 400000 lines
Test #14:
score: 5
Accepted
time: 543ms
memory: 6364kb
input:
199999 500000 36761637 237173860 880565208 32392894 307993651 574350707 296680562 204730334 575954218 181883380 871338331 410068293 221323949 3192670 172141305 166314386 11836676 299978135 70182567 483748336 573472201 202396463 352049969 61071000 28272671 214329894 56200021 910331248 29044594 589295...
output:
257234747 35528599 40078266 293188289 648443211 158897300 694022151 154234799 208025514 491621258 356180361 497973452 209886790 183009583 841642995 387643607 368392613 471225708 731437594 587323993 112304690 423485056 303322926 209411806 119126639 503649181 867013811 52978742 911991514 610813407 638...
result:
ok 400000 lines
Test #15:
score: 5
Accepted
time: 801ms
memory: 16440kb
input:
200000 500000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
output:
0 0 0 0 0 0 0 0 934911411 651331060 654094081 135195651 786152385 827556849 592841590 665269254 818807422 44026966 1452212 334481665 922836002 219308448 614660214 597589099 614659708 344197115 668250481 377664159 243999389 569302726 346804404 881562862 91055926 58586079 253653673 397342816 327686689...
result:
ok 400000 lines
Test #16:
score: 5
Accepted
time: 669ms
memory: 16356kb
input:
200000 500000 560005139 16518435 100778233 333488606 351070691 411293764 983501871 637064280 300416088 764546552 390098386 346535403 138872373 534643233 962243486 93491004 189928018 560233296 190270885 585014759 652306459 826540361 36961477 511017210 17076742 587149699 147680588 27667310 692678716 7...
output:
750303435 942641978 305346687 342571320 165891240 87472128 519380365 843481081 373526717 791612084 572601022 429519395 30461252 184356828 788446140 192576130 181266363 402883783 664281865 308112968 770176152 154959845 627710243 244158122 615436143 990404949 752919036 853591032 337156399 818469264 44...
result:
ok 400000 lines
Test #17:
score: 5
Accepted
time: 661ms
memory: 17656kb
input:
200000 500000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
output:
365114916 752426234 248681210 50921616 384320009 925543000 320381841 199791061 685886112 157306078 949364868 683557897 604086846 847180341 616447113 140058060 583909137 504968736 841014395 611530904 730572242 124936676 138986224 574260872 515636096 725431835 287151767 818590125 288797442 606917778 5...
result:
ok 400001 lines
Test #18:
score: 5
Accepted
time: 662ms
memory: 16424kb
input:
199999 499999 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
output:
0 0 0 0 0 0 0 187609344 828549791 249761989 984938631 95753044 330825945 91415496 548822456 822395359 632464505 30406829 481804256 14306027 174436633 390608300 182054570 474689920 706734785 459479155 69868881 147391902 122284987 799816391 400379176 531835696 582004723 966415881 682065767 680102833 7...
result:
ok 399999 lines
Test #19:
score: 5
Accepted
time: 680ms
memory: 16864kb
input:
200000 500000 383766608 221212007 649108515 452960113 283014121 968019797 461745475 291428702 688008547 490711023 84175473 832790540 701439021 988788507 126869461 265278956 937022281 276655352 658369389 757685734 520620495 226926164 957781386 863320019 668212074 315263283 475248976 943500546 8813508...
output:
642126582 122570873 345705564 351011865 294652734 192551231 256995741 732137032 67042506 26727297 706179445 879182313 609893249 419887947 402908660 585759902 536282204 775498856 470719284 160166149 374075772 431189409 227141384 651691824 616002593 621588578 504944618 39110740 456477636 333975155 917...
result:
ok 400000 lines
Test #20:
score: 5
Accepted
time: 676ms
memory: 16432kb
input:
200000 500000 55761409 605219716 39487783 519537332 660476042 491686494 233727251 675493970 572051901 845531901 25395448 295075307 346371403 839919498 706671932 479355953 43836525 162132576 947262495 471573578 156777618 13942921 842056240 798538832 555674510 583098462 724082389 103963601 242590824 8...
output:
14262207 542363995 523198380 43347577 822442521 502790007 978962463 685481496 939523095 102067671 366949588 136569113 496773410 879561777 168092977 422516447 315402074 629688167 361107232 325967482 108169769 831551145 128901039 818970323 257458262 788865388 750353791 894938900 7113920 673959918 1720...
result:
ok 400000 lines