QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#634027 | #8139. Ayano and sequences | Layn | TL | 3832ms | 316468kb | C++14 | 3.0kb | 2024-10-12 16:35:22 | 2024-10-12 16:35:22 |
Judging History
answer
#include<bits/stdc++.h>
#define mid (l+r>>1)
#define ls l,mid,p<<1
#define rs mid+1,r,p<<1|1
#define mp make_pair
#define rg register
#define il inline
using namespace std;
const int N=500010,inf=1000000000;
int n,m,a[N];
bool flag[N*4];
unsigned long long b[N];
set<pair<int,int> >lft;
struct mat {
unsigned long long c[3][3];
il mat(){memset(c,0,sizeof(c));}
}E,t[N*4],tag[N*4];
il int read() {
int x=0;char ch=getchar();
while(ch<'0'||ch>'9')ch=getchar();
while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
return x;
}
il mat get_m(int w) {
mat x;
x.c[0][0]=x.c[1][1]=x.c[1][2]=x.c[2][2]=1;
x.c[0][1]=x.c[0][2]=w;
return x;
}
il mat mul(mat x,mat y) {
mat z;
for(int i=0;i<3;i++)for(int j=i;j<3;j++)for(int k=i;k<=j;k++)
z.c[i][j]+=x.c[i][k]*y.c[k][j];
return z;
}
il void turn(int p,mat w) {t[p]=mul(t[p],w),tag[p]=mul(tag[p],w),flag[p]=1;}
il void pushdown(int p) {turn(p<<1,tag[p]),turn(p<<1|1,tag[p]),tag[p]=E,flag[p]=0;}
void update(int l,int r,int p,int ql,int qr,int w) {
if(l>=ql&&r<=qr)return turn(p,get_m(w));
if(flag[p])pushdown(p);
if(mid>=ql)update(ls,ql,qr,w);
if(mid<qr)update(rs,ql,qr,w);
for(int i=1;i<3;i++)t[p].c[0][i]=t[p<<1].c[0][i]+t[p<<1|1].c[0][i];
}
unsigned long long query(int l,int r,int p,int ql,int qr) {
if(l>=ql&&r<=qr)return t[p].c[0][2];
if(flag[p])pushdown(p);
unsigned long long res=0;
if(mid>=ql)res+=query(ls,ql,qr);
if(mid<qr)res+=query(rs,ql,qr);
return res;
}
void build(int l,int r,int p) {
tag[p]=E,t[p].c[0][0]=r-l+1;
if(l==r)return;
build(ls),build(rs);
}
void init() {
for(int i=0;i<3;i++)E.c[i][i]=1;
build(1,n,1);
}
int main(){
n=read(),m=read(),init();
for(rg int i=1;i<=n;i++)a[i]=read();
for(rg int i=1;i<=n;i++)if(a[i]!=a[i-1])lft.insert(mp(i,a[i]));
lft.insert(mp(n+1,0));
for(rg int o,l,r,w,cs=1;cs<=m;cs++) {
o=read(),l=read(),r=read(),w=read();
if(o==1) {
auto L=lft.upper_bound(mp(l,inf));--L;
auto R=lft.upper_bound(mp(r,inf));
int tl=L->first,tr=(R->first)-1,wl=L->second,wr;
--R,wr=R->second,++R;
//printf("case%d: %d %d %d %d\n",cs,tl,tr,wl,wr);
for(auto i=L;i!=R;) {
auto j=i;
++i,b[j->second]+=query(1,n,1,j->first,(i->first)-1);
lft.erase(j);
}b[w]-=query(1,n,1,l,r),lft.insert(mp(l,w));
if(l>tl)b[wl]-=query(1,n,1,tl,l-1),lft.insert(mp(tl,wl));
if(r<tr)b[wr]-=query(1,n,1,r+1,tr),lft.insert(mp(r+1,wr));
update(1,n,1,1,n,0);
}
else {
update(1,n,1,l,r,w);
if(l>1)update(1,n,1,1,l-1,0);
if(r<n)update(1,n,1,r+1,n,0);
}
}
for(auto i=lft.begin();i!=lft.end();) {
auto j=i;
++i;
b[j->second]+=query(1,n,1,j->first,(i->first)-1);
}
for(rg int i=1;i<=n;i++)printf("%llu ",b[i]);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 16ms
memory: 288360kb
input:
5 6 1 2 3 4 5 2 2 4 1 1 2 3 3 2 3 4 3 1 3 5 4 2 1 5 2 1 1 3 2
output:
2 12 12 36 0
result:
ok single line: '2 12 12 36 0 '
Test #2:
score: 0
Accepted
time: 28ms
memory: 287312kb
input:
10 10 9 2 8 8 6 5 4 8 5 3 2 2 6 268792718 2 7 8 125908043 2 2 3 150414369 2 6 10 856168102 2 4 5 274667941 1 1 9 6 2 2 6 646837311 2 6 6 105650419 2 7 9 254786900 2 1 7 73936815
output:
0 1795206697 5993176714 2215968376 4768635998 46271691633 0 5629806604 0 0
result:
ok single line: '0 1795206697 5993176714 221596...8 46271691633 0 5629806604 0 0 '
Test #3:
score: 0
Accepted
time: 12ms
memory: 287264kb
input:
100 100 59 96 34 48 8 72 67 90 15 85 7 90 97 47 25 44 69 6 86 32 57 47 21 9 63 10 75 35 61 11 75 100 50 53 15 40 35 86 97 77 27 30 35 91 72 87 56 25 95 70 60 22 47 49 68 61 35 87 16 54 20 91 35 39 64 21 58 44 5 20 61 87 66 74 45 64 9 84 1 26 32 63 53 33 96 47 73 94 45 32 99 14 44 48 1 78 7 10 68 52 ...
output:
274832111654 0 0 0 309880184 347085980 0 5208679581 0 0 1391288895991 462582810805 0 309880184 0 309880184 0 2202105800064 0 1470341419 1160461235 0 0 2697359985855 1041257940 46672170424 0 951255722094 0 0 1329201652617 121425405126 683986398348 138178909497 1470341419 0 0 2492776390926 80323798299...
result:
ok single line: '274832111654 0 0 0 309880184 3...94 609693254112 307568016399 0 '
Test #4:
score: 0
Accepted
time: 24ms
memory: 288068kb
input:
5000 5000 987 4237 3891 429 4358 1145 851 4174 4670 3571 3747 3238 391 3689 2144 3561 3383 56 1508 777 4705 733 4730 2292 2524 3519 1996 588 3682 2682 1493 270 4145 885 3015 644 2669 4757 439 387 4020 3944 1420 1750 1968 4067 2771 1865 809 2941 1286 1478 1433 3465 2064 1100 1926 2912 3971 1266 3923 ...
output:
1264113586735714 112938905619174 3426351370 0 3616678527569466 12410599127 20863739455 1943199759422496 6860659882 24097078636 4940352344 3066105550 4940352344 8984247757 0 0 1873308016 690360017267298 1463634140028344 34786416053526 10565974962 491847076791519 0 3066105550 337181826086845 954432374...
result:
ok single line: '1264113586735714 1129389056191...2 17437388085 2534760806780036 '
Test #5:
score: 0
Accepted
time: 584ms
memory: 293400kb
input:
100000 100000 9411 13081 2149 19907 93611 24114 59730 5867 96529 35050 21890 2981 87777 82418 96659 18374 76106 7614 79526 45826 56158 33510 42240 53971 75573 98727 13513 35449 65290 67552 80720 51348 94140 32021 97828 38348 52399 51728 27676 75498 22825 15163 89905 26204 15157 2855 99583 81109 1142...
output:
2860862817585182004 0 0 668421922369962250 0 4558260292 170686179720145772 270419400917769555 823080596 30396324352 991325503472415378 549309244400642225 1470105139512235415 0 1216640397961225546 21449668079 0 0 5381340888 197095337844692543 11450152672832485 823080596 345580727782852526 21449668079...
result:
ok single line: '2860862817585182004 0 0 668421...141382845 0 920528238127173667 '
Test #6:
score: 0
Accepted
time: 575ms
memory: 294700kb
input:
100000 100000 25539 29221 6895 82089 18673 2890 99009 89855 30685 39232 82330 30021 87868 84659 66982 66291 48020 79364 42952 42770 19906 81288 92853 52547 89430 17447 7734 93014 55411 67422 67242 28915 3728 75454 99937 32948 87129 81803 14914 8713 63118 33277 88390 60658 49154 63938 46394 72649 204...
output:
3711628643750554324 556362386091535043 0 8028405448 8028405448 219909499354732110 0 1323849903041530801 14525054661 29347414077490544 980768499542767970 0 234259419233115560 8028405448 0 0 13435740174125371 8028405448 0 1268120972702792862 85232791231015303 8028405448 7591907024531183667 0 0 6227380...
result:
ok single line: '3711628643750554324 5563623860...31283976 27233070503118890 0 0 '
Test #7:
score: 0
Accepted
time: 580ms
memory: 293524kb
input:
100000 100000 76259 10770 87448 3054 67926 81667 95184 41139 64840 76118 18577 22469 96470 78388 28793 14208 95743 59626 40970 7011 7847 4874 362 94226 68695 27655 1955 9363 69723 34588 10660 47697 13315 51590 34750 3356 21858 79173 2151 98823 46514 51392 54171 52009 7343 81918 93206 64189 35767 190...
output:
1296206533755864325 3408617157162819 1367176386 292548752396599025 0 0 1367176386 14288338007 2734352772 1051580445916368582 3071278704 4068600777268612311 618819063961521440 4675194818878852042 362754832564412528 5790497232 307885871989844920 455725462 0 5790497232 0 931292207145677471 0 1066559415...
result:
ok single line: '1296206533755864325 3408617157...0759545046 5915105370229767921 '
Test #8:
score: 0
Accepted
time: 591ms
memory: 294480kb
input:
100000 100000 92387 35422 24898 32532 92988 84636 99872 57831 31700 47597 79017 25316 96560 4822 31820 62125 8873 31377 38988 12468 71596 52652 40575 1313 82552 37864 96176 34224 84035 10267 29886 57968 31414 95022 61051 97957 89292 9248 89389 23526 19511 12610 95760 86463 65531 43001 40017 88433 26...
output:
171366078874572813 20509648584758088 2437426492745132371 0 960915322 0 960915322 1921830644 156529249442565108 0 0 577750733721075019 78581487497386145 27517495958 2719915459771023390 0 960915322 1960237471028313164 0 4545736696214496575 0 336463929447759705 3843661288 1921830644 22760558906 9609153...
result:
ok single line: '171366078874572813 20509648584...3904163920 1374231424175143263 '
Test #9:
score: 0
Accepted
time: 596ms
memory: 294752kb
input:
100000 100000 8515 51563 5451 94713 9537 30709 63343 41819 65855 51779 39457 85060 96650 74359 93631 10042 80788 11639 69710 76709 68048 33133 23893 75696 96409 23880 14590 91789 74156 10137 49112 35534 41001 71159 63159 35661 91318 39323 76627 89445 35612 30725 94245 20918 99528 36789 86829 79973 8...
output:
54191958 0 343919527782549352 9031993 0 842744505716284651 10535466989 4520361277 0 18063986 1281928441250648448 3876431406219851657 33832389186580283 203761488938235284 246691638186991544 0 2299774162079501436 0 36561691059466635 0 0 124203447330148627 273331593346351168 480610589593712254 18063986...
result:
ok single line: '54191958 0 343919527782549352 ...49109467 0 2983109225563613099 '
Test #10:
score: 0
Accepted
time: 583ms
memory: 293700kb
input:
100000 100000 91939 407 10197 24191 58791 9486 68030 25807 11 88665 32600 12100 29445 33496 96658 57959 28510 83389 67729 40950 55989 80911 31402 17375 42970 99496 8811 8138 88468 10007 92530 21612 83292 81887 97972 62965 58752 36694 96568 46851 75905 91943 60026 88076 57717 97872 936 71513 74917 52...
output:
1878499310067731347 0 0 157334864681509345 0 594964574666066187 0 5582057088 199633267174389376 0 6083714190617 2574062040646687147 148402260162 0 171103271643568965 91941775271241949 30136542084 731547080385 259559763726095800 9101796151 0 1274850907901014267 7699837152 15187121185 5308948889437840...
result:
ok single line: '1878499310067731347 0 0 157334...7203933 0 609748350226766294 0 '
Test #11:
score: 0
Accepted
time: 3610ms
memory: 316336kb
input:
500000 500000 30518 196518 274071 359971 50121 204862 343967 173607 119138 190754 219513 171337 183499 49873 42337 161387 397647 495917 413076 418417 368000 422012 195703 305826 26356 334728 35984 133227 226371 132864 493387 111196 258251 76565 244054 213672 267148 179390 200005 67050 46349 2772 499...
output:
1886455206 0 11469056700014505036 0 0 0 975642600 997216260409279885 11578575005803125745 1886455206 0 975642600 12533853350530616892 1886455206 16307373482519741808 0 0 0 0 1670105078527398143 0 9754424448487156860 0 0 0 6418184959657184670 12528246323403061929 0 1886455206 0 25620138333 1886455206...
result:
ok single line: '1886455206 0 11469056700014505...7191720 241579956214658397 0 0 '
Test #12:
score: 0
Accepted
time: 3832ms
memory: 316356kb
input:
500000 500000 146646 21171 278816 489449 399375 150934 115950 390299 118702 462232 12657 231081 450885 376306 12660 109304 145369 371 343798 182657 431749 37086 335916 147505 372917 420744 97501 58088 249196 432734 236805 121466 67838 19997 270355 275569 134582 409464 254538 100264 486641 88182 1978...
output:
0 11504628261216105965 0 18122741101773120227 8717179869060371543 1411420630 0 9865628745813133295 0 85914464049 0 0 5865956851485221132 19340415 0 7709072391904018508 0 0 17837545093477132546 4372689275 163778467626485377 0 9801741718309261386 712312278 0 477431720118218861 0 5648209278489764131 0 ...
result:
ok single line: '0 11504628261216105965 0 18122...833467774369377790 0 705710315 '
Test #13:
score: 0
Accepted
time: 3686ms
memory: 316272kb
input:
500000 500000 230070 37311 92074 118927 491732 129711 112126 41583 52857 299118 273097 33928 250975 445843 207175 57221 117284 247929 241816 479602 219689 184863 410721 21888 219478 230953 191722 207141 430804 199900 288735 407544 218641 463430 105167 178681 469312 106835 341776 357671 170038 482105...
output:
0 13340751016 8690217281 15491324220649796704 0 0 61287101115 439745527294676378 58217962 4062400828333094732 5604447928407345028 28288673734 2423670022850079087 8063764403 0 0 0 0 3800131436853444525 0 10479489331829094172 0 14012838015759666616 5142594413 16753981684 4379414306477261672 1371107611...
result:
ok single line: '0 13340751016 8690217281 15491...28337348 8690217281 26462710 0 '
Test #14:
score: 0
Accepted
time: 3750ms
memory: 316272kb
input:
500000 500000 313494 86155 96820 472596 340986 299976 416813 225571 487013 103301 832 126376 83769 272276 177498 5138 430414 219679 139834 19651 316142 108449 294039 87759 257527 73865 285943 132001 420924 467067 275257 417815 28228 406862 439980 273281 304042 61102 461717 115078 143035 100219 30523...
output:
781019416028176674 4470032212 0 3969573760 10759978474 0 7482269202 9302947471319339716 7482269202 0 7179668777211616794 6881482956595236334 0 3969573760 0 0 0 7482269202 7218085322036685310 3277709272 78545302238286574 0 0 6289703450393976444 384949437353265951 5426267598650008414 11755890988492783...
result:
ok single line: '781019416028176674 4470032212 ...8463328 17743085104227237892 0 '
Test #15:
score: 0
Accepted
time: 3715ms
memory: 315876kb
input:
500000 500000 396918 167704 410077 134778 190239 311457 380284 442263 453872 374779 293976 153416 383860 374518 372013 420351 178137 467238 70557 316596 379890 256227 401548 462143 71384 192585 380165 281054 102533 42745 18675 203893 337815 382998 433577 143689 138771 291177 48955 180996 359136 4614...
output:
0 1906720271790051011 4900529393996989076 1905504913666103104 5874982170557448726 0 12038499438166745120 132717410600115864 0 12279872118 11193532279424946392 0 5391237996 8835555057 8720466004815454016 5391237996 0 17355671985063637834 0 10162486464729493080 693094031933589004 0 1073040932080932142...
result:
ok single line: '0 1906720271790051011 49005293...2861616359 9732639604756851604 '
Test #16:
score: 0
Accepted
time: 3703ms
memory: 316336kb
input:
500000 500000 13046 183844 414823 264255 315301 290234 184972 93547 388028 211665 54415 213159 183950 200951 342336 92460 150051 247500 1279 80836 443639 436708 9057 303822 417945 2793 474386 205915 125357 342615 37901 214164 455915 326431 268390 238289 197693 488548 103489 471107 299429 79552 16949...
output:
82564028389 447927181490388002 8092103670626473172 870460794 1760603927501018549 6499113058127693275 96717866 9333537660080476727 9119079563522890845 2063758602974739867 290153598 1369939246031544610 489039682531297394 0 0 0 0 0 967178660 16754951341818015903 96717866 870460794 22677350207 0 1789863...
result:
ok single line: '82564028389 447927181490388002...2922 967178660 0 18578462376 0 '
Test #17:
score: 0
Accepted
time: 3626ms
memory: 315888kb
input:
500000 500000 129174 232688 195377 426437 164554 460498 456955 310239 322183 15847 347559 240199 292552 270488 4147 73082 397774 251954 399297 153589 231579 360294 116567 178205 231802 313002 68607 163480 339669 109781 57127 467538 265502 302567 103202 75993 32423 251327 499238 228514 48233 164963 1...
output:
0 0 0 0 0 11965175796 3168489725154733543 3845541240480111010 0 0 0 9335928547741475183 0 0 6406897392211686483 111129369012893634 0 0 11965175796 0 3654245371217525150 0 8494364114453054429 3941664213192603475 0 5254752683520608140 2867546421380988204 16713709561549491216 6596556504 0 3524553925868...
result:
ok single line: '0 0 0 0 0 11965175796 31684897...2930053198 9890204392714577468 '
Test #18:
score: 0
Accepted
time: 3685ms
memory: 316468kb
input:
500000 500000 179894 24637 8634 280107 481104 439275 453130 494227 256339 287326 107999 75751 92642 96921 474470 20999 369688 499512 330019 450534 328032 8072 467180 19884 45659 155914 130124 312533 297086 409652 300546 10512 140497 245999 405311 203298 399857 448698 86476 261728 455822 58885 309569...
output:
0 5134049757651035556 0 6994797176282743598 0 8354612987 0 0 11106805744509506682 220940386717565601 0 9385390049444241707 4832725322289376626 0 13743933800356936916 17046519039 4682266741024494821 0 0 4248607248945628722 0 8605192132 11084798964 25821461686 8400516867331984740 575067205073926990 0 ...
result:
ok single line: '0 5134049757651035556 0 699479...19039 10576202029461102932 0 0 '
Test #19:
score: 0
Accepted
time: 3617ms
memory: 316348kb
input:
500000 500000 296022 73481 13380 442288 106166 385348 225113 178215 223198 124212 144246 135494 392733 166459 444793 468916 182818 3967 228037 247479 391780 155850 74689 118459 392220 241930 224345 204690 44102 209522 287068 296591 225892 222136 431612 41002 234586 178773 173713 19135 396115 144296 ...
output:
55797934 1610715821276307598 0 55797934 17200028370012469093 0 0 7434688437169251853 7694629059900588149 15424058336441119339 10375671359407939374 9122586936474983074 10324749617467589113 55797934 0 55797934 111595868 2416949386375159400 111595868 55797934 0 55797934 0 2154662025164164480 2517288151...
result:
ok single line: '55797934 1610715821276307598 0...026349074969 40549323267756268 '
Test #20:
score: 0
Accepted
time: 3619ms
memory: 316324kb
input:
500000 500000 379446 155030 293934 39062 488123 88317 221289 362203 157354 428394 437390 195238 192823 492892 139308 416833 154733 251525 158759 287527 179721 46731 214903 492843 238781 52138 318566 162255 225710 9392 30486 274157 35479 165568 233721 411410 69316 408848 293655 85054 144920 262410 44...
output:
5894081435531045645 4417482576161732665 27340498473 1839464988 10928139689904245981 87527970099 0 100011140687256664 7405928646015886858 1039257449 0 229494571154 111052358730780006 0 0 0 1875882340585647693 0 0 11922148736015043708 156603910113 522468277188132467 1039257449 0 0 885968700 0 12417235...
result:
ok single line: '5894081435531045645 4417482576...559166954009403 0 0 1039257449 '
Test #21:
score: 0
Accepted
time: 3631ms
memory: 316336kb
input:
500000 500000 405440 88704 61481 472140 115810 158854 243034 305150 280684 361360 50516 54301 478790 43678 46138 279893 389899 460260 302881 66499 199500 254572 454419 333657 243179 161234 229965 91136 437826 126886 406880 164913 490362 385934 153747 340219 14676 246017 62847 187713 207556 37069 240...
output:
6548223169226973615 0 0 11984730716316855130 362150769093765603 17232455178590307784 2054599425510440960 0 0 0 10191045193930145323 0 0 5654362711026931040 1595060805148815162 1993952857578283371 0 0 0 0 0 0 0 0 6664510020509101189 17910932012604117517 0 8595668679714110248 0 0 1709782626751760276 0...
result:
ok single line: '6548223169226973615 0 0 119847...8830 0 0 8543230275237472462 0 '
Test #22:
score: 0
Accepted
time: 1738ms
memory: 287720kb
input:
7000 500000 3569 5548 5739 3809 6063 631 4913 6138 2543 4542 4956 1045 6880 111 5357 6810 3326 4523 1899 547 2440 4350 2928 2233 3036 3250 6186 997 1138 4052 4298 992 5949 2366 1856 6627 110 92 2893 824 3552 4479 3759 6975 3373 6949 2833 3329 1063 2310 96 4513 4368 1881 5439 1078 6139 6781 1444 6755...
output:
6740217347512014087 12285949254238780529 14682638984663597269 11282765686671541586 10724653500757853013 14439847768056340775 11095543533317211070 8084159657959201539 12434724688038088198 14639850776207351894 7160350029891952511 10876580269757133858 7441994176152120399 13225765240841390291 8912028490...
result:
ok single line: '6740217347512014087 1228594925...6808115169 9247380487007246796 '
Test #23:
score: 0
Accepted
time: 1733ms
memory: 288780kb
input:
7000 500000 3289 5393 3484 1287 6317 6704 3192 4126 699 6429 5100 1085 4482 3352 976 2727 240 5569 1621 3492 2189 2936 3437 3616 3597 5458 3703 6858 1258 2923 3524 2558 6240 6502 4861 1228 5840 2463 4130 2742 6653 6402 5836 1430 5561 1032 2644 5869 2681 4265 5914 4565 3653 1213 6039 313 2922 6402 22...
output:
7006435996534227250 15748904376011753246 11381537088425385319 14483562943581027121 5903522593812485001 11735801745084987186 9285387248010127752 11745455426526049481 7374099346616397371 10985869653818485032 15815600093268716814 3201129032790818841 14231044690844967650 8042824493508767819 111641735773...
result:
ok single line: '7006435996534227250 1574890437...1902267918 5570324551114022497 '
Test #24:
score: -100
Time Limit Exceeded
input:
500000 500000 188417 11045 192742 84765 406675 286673 40072 357114 115854 306611 140347 476636 187572 266082 438195 156348 389962 459831 29640 443541 114937 473713 52755 148295 217454 433075 479924 89911 356571 269601 380239 214636 227635 248935 316969 175636 51569 436242 133072 301149 336946 101812...