QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#725351 | #9604. Cyberangel | lotus_f | 10 | 159ms | 34592kb | C++14 | 1.8kb | 2024-11-08 17:13:54 | 2024-11-08 17:13:55 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int __int128
int n,m;
int a[1000010];
int tot=0,lsh[1000010];
vector<int> vec[1000010];
int l[1000010],r[1000010];
void write(int x)
{
if(x==0) return putchar('0'),void();
int tot=0,dig[40];
while(x!=0) dig[++tot]=x%10,x/=10;
for(int i=tot; i>=1; --i) putchar(dig[i]+'0');
}
signed main()
{
long long re; cin>>re,n=re,cin>>re,m=re;
lsh[++tot]=m+1;
for(int i=1; i<=n; ++i) cin>>re,a[i]=re,lsh[++tot]=a[i];
sort(lsh+1,lsh+tot+1),tot=unique(lsh+1,lsh+tot+1)-lsh-1;
for(int i=1; i<=n; ++i) vec[lower_bound(lsh+1,lsh+tot+1,a[i])-lsh].push_back(i);
int sum=0;
for(int i=1; i<=n; ++i) l[i]=1,r[i]=i,a[i]=tot,sum+=lsh[a[i]]*(i-l[i]+1)*(r[i]-i+1);
int ans=0;
for(int i=tot; i>=1; --i)
{
int sum1=sum;
for(int j:vec[i])
{
for(int k=1; k<j; ++k)
{
sum-=lsh[a[k]]*(k-l[k]+1)*(r[k]-k+1);
r[k]=min(r[k],j-1);
sum+=lsh[a[k]]*(k-l[k]+1)*(r[k]-k+1);
}
for(int k=j+1; k<=n; ++k)
{
sum-=lsh[a[k]]*(k-l[k]+1)*(r[k]-k+1);
l[k]=max(l[k],j+1);
sum+=lsh[a[k]]*(k-l[k]+1)*(r[k]-k+1);
}
}
for(int j=0; j<vec[i].size(); ++j)
{
int wz=vec[i][j];
sum-=lsh[a[wz]]*(wz-l[wz]+1)*(r[wz]-wz+1);
l[wz]=1,r[wz]=(j==vec[i].size()-1?n:vec[i][j+1]-1),a[wz]=i;
sum+=lsh[a[wz]]*(wz-l[wz]+1)*(r[wz]-wz+1);
}
int sum2=sum;
for(int j:vec[i]) sum2-=lsh[a[j]]*(j-l[j]+1)*(r[j]-j+1);
int cnt=(n+1)*n/2,lst=0;
for(int j:vec[i]) cnt-=(j-lst)*(j-lst-1)/2,lst=j;
cnt-=(n-lst+1)*(n-lst)/2;
ans+=lsh[i]*(sum1-sum2-cnt*lsh[i]);
// cout<<"sum: "<<sum1<<' '<<sum2<<' '<<cnt<<' '<<ans<<'\n';
// cout<<"a:\n";
// for(int j=1; j<=n; ++j) cout<<lsh[a[j]]<<' '; cout<<'\n';
// for(int j=1; j<=n; ++j) cout<<l[j]<<' '<<r[j]<<'\n';
}
write(ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 8ms
memory: 32384kb
input:
500 995106803 150608560 532482040 23208958 442246216 2917205 948292264 962672628 610596054 69010421 206923685 605381259 560683057 374135360 323257595 224120348 773540778 414928542 327812091 524797091 241525558 228068400 618957683 365266079 992727350 87923118 536412424 557677355 392087162 158151043 2...
output:
59854856571283884484109
result:
ok single line: '59854856571283884484109'
Test #2:
score: 5
Accepted
time: 3ms
memory: 30356kb
input:
500 998177916 831776477 192175032 961088945 183712798 579677277 717304183 832903374 615887036 442602679 409553238 129885355 100943200 343489036 687786479 430405465 777511373 204923633 343819665 25948944 842220326 549608142 468749656 142098334 933571884 251697899 59109537 789796162 785935340 73343227...
output:
60246542713395218641133
result:
ok single line: '60246542713395218641133'
Test #3:
score: 5
Accepted
time: 3ms
memory: 30208kb
input:
500 997709021 801389775 126836923 995423900 219539434 339502026 400019091 497938039 72089859 869274947 184571531 95809171 59962362 417254404 298805403 917564456 174720088 556735156 56414432 280677373 588219772 522819920 10779045 716982277 910938390 725089141 281874084 483114735 734955935 987450129 1...
output:
60181661281845334448315
result:
ok single line: '60181661281845334448315'
Test #4:
score: 5
Accepted
time: 7ms
memory: 32388kb
input:
500 999864497 627827881 25595645 328673824 270847919 489497074 903403290 421254283 159758901 6189614 343812596 911516439 60128926 482199981 830880981 367241232 57161002 550510139 120327439 186258690 809283515 227915662 506674645 430185166 372234930 650467661 69593303 51637417 704635555 894789119 531...
output:
60396928745198318213258
result:
ok single line: '60396928745198318213258'
Test #5:
score: 5
Accepted
time: 3ms
memory: 30364kb
input:
500 998970591 594389705 43008089 396347059 986339673 905846754 807045742 470917409 639614371 637270684 136879653 58845444 425605406 777235535 28588928 139911753 103232624 154106955 961479631 886521757 107881189 253056135 620990994 615378167 665480349 722387860 856766009 760620628 65813484 801372010 ...
output:
60301465403020284987744
result:
ok single line: '60301465403020284987744'
Test #6:
score: 5
Accepted
time: 3ms
memory: 32260kb
input:
500 989354834 660461 1884309 2515211 2982180 6020191 8648567 9104058 9622568 11387149 15218527 15757206 15839199 17545553 18657144 23829639 23974929 24203477 25293790 29677662 31112007 32068246 33915814 39839268 40549810 42735311 43467522 44090402 46074234 48410214 49938093 51091987 52098376 5237871...
output:
40532371095490200672323
result:
ok single line: '40532371095490200672323'
Test #7:
score: 5
Accepted
time: 3ms
memory: 30356kb
input:
500 995856121 995856021 993286190 992428714 987211623 986866652 973993987 970908624 965906992 962384596 961444659 959872088 959274665 954413029 954237972 952206028 950914253 936598037 936541012 936315259 933876938 931901616 929610770 928438496 928418851 927097736 925343918 922758477 921599847 915514...
output:
41163428747490462739833
result:
ok single line: '41163428747490462739833'
Test #8:
score: 5
Accepted
time: 7ms
memory: 30292kb
input:
500 996970428 55157343 782882347 768451599 768451599 216444512 768451599 26520824 371900895 628553310 870731874 768451599 189471193 371900895 564613440 371900895 870731874 443892194 628553310 515311766 626042362 953946357 371900895 139227361 443892194 766070123 766070123 953946357 953946357 37190089...
output:
56893191095878174612719
result:
ok single line: '56893191095878174612719'
Test #9:
score: 5
Accepted
time: 8ms
memory: 32280kb
input:
500 999683066 223727705 480369708 112292804 481160745 224317240 481725729 45280199 488390505 224431750 489839974 117626392 490591180 224711896 490697505 17917789 491413367 224744745 494790152 118515418 495247247 224837576 505897124 58691469 507771381 225294818 507936116 120348431 508509141 227390703...
output:
53154300124913676131137
result:
ok single line: '53154300124913676131137'
Test #10:
score: 5
Accepted
time: 4ms
memory: 30224kb
input:
500 996680038 197437207 458179304 97398864 458338863 198111821 462929198 47263622 464290325 198266716 467555428 100906560 470063484 199483735 472198668 21866514 472442955 200116781 473511671 101048946 476465465 202606998 477951175 47358497 485263524 203886219 488787675 102911236 490111517 207661861 ...
output:
52269022842767688419390
result:
ok single line: '52269022842767688419390'
Test #11:
score: 5
Accepted
time: 3ms
memory: 32312kb
input:
500 996836518 225663257 487415392 113657597 489627476 229686724 493005821 55589679 494314979 231928299 495884741 113824536 497766188 234758176 499178014 24183623 500198901 237391031 500395616 114684268 501242775 240056411 504928824 57255729 508780751 240102366 510732434 116605228 511761619 241162385...
output:
52901323000404343054947
result:
ok single line: '52901323000404343054947'
Test #12:
score: 5
Accepted
time: 4ms
memory: 30280kb
input:
500 997308361 734384892 487928623 885511190 485978519 732782900 485503315 943352135 485139910 731135061 483452593 884499732 480665632 728846479 470610017 966846915 469944921 726748288 466928565 884344389 466856622 726342874 466668864 941970606 466454046 723150867 464794706 884103531 462749291 723117...
output:
52771619017756982130181
result:
ok single line: '52771619017756982130181'
Test #13:
score: 5
Accepted
time: 3ms
memory: 30164kb
input:
500 998995500 707934238 443951641 841012116 443699773 707580586 443209459 924668947 442662521 706274831 442081118 838685438 439562971 705821480 437121050 970118929 432994869 701550583 431651576 838650253 430926740 701508876 419349462 922548610 417491326 696577019 416970255 837263122 413262645 687275...
output:
53853636162421336664462
result:
ok single line: '53853636162421336664462'
Test #14:
score: 5
Accepted
time: 3ms
memory: 30268kb
input:
500 996650138 765626812 453357781 885559897 453256645 761785891 450241520 934514768 446699514 755330669 443755169 884997036 443304254 754923200 434085582 970099818 430508063 754466272 425416574 884513817 424764093 754038009 423164779 934372987 423139345 738573359 422204416 884460993 417674914 732117...
output:
52624776032982600280160
result:
ok single line: '52624776032982600280160'
Test #15:
score: 5
Accepted
time: 7ms
memory: 30352kb
input:
500 999700415 582362183 192179044 534193232 257560075 715029649 684274335 816995706 839543380 688559527 634842016 384705910 136286773 34458146 605084919 279247643 786036528 266661206 203719326 482073421 104473700 627545971 142037098 832947668 418619361 115575142 982412566 388148602 468755125 3841767...
output:
60332370236440636673573
result:
ok single line: '60332370236440636673573'
Subtask #2:
score: 5
Accepted
Dependency #1:
100%
Accepted
Test #16:
score: 5
Accepted
time: 138ms
memory: 30428kb
input:
4000 999415835 325434705 485976668 926029739 370138494 732722191 208960936 412781133 493804459 4441873 29594424 212942231 469635956 113686686 586697026 150736460 253382523 181223360 944337109 416622295 467119741 260653459 645818255 435141298 973596863 434331375 615989573 998308216 741169188 12392168...
output:
3970595078712735751359371
result:
ok single line: '3970595078712735751359371'
Test #17:
score: 5
Accepted
time: 133ms
memory: 30380kb
input:
4000 999802203 649599118 250242603 68728072 326316859 495033111 280504659 609604408 220764914 987811589 424440173 93884997 758158169 950052420 735205708 754774713 403044281 925970729 869867857 793650314 144640266 692849593 268339283 395685942 279053437 386372770 454100953 954177968 293123588 2209313...
output:
3973569086333886235045817
result:
ok single line: '3973569086333886235045817'
Test #18:
score: 5
Accepted
time: 133ms
memory: 32560kb
input:
4000 999877964 366336061 5210161 430101309 335127841 327462116 704349665 757207803 152973338 175661848 115244100 300447019 919391649 774029717 151987390 197961326 457019353 202390579 681204583 808751729 731297172 473513672 36167641 621014106 514616325 491331963 66505607 355272432 776013920 51048286 ...
output:
3974047727292952591000299
result:
ok single line: '3974047727292952591000299'
Test #19:
score: 5
Accepted
time: 135ms
memory: 32532kb
input:
4000 999849325 314868515 254328634 886011412 690249804 131156418 749422062 944497587 939604455 255160614 561080726 368272617 204518254 436529716 59820879 562032608 325312316 181182732 364045397 521201470 285317185 14219931 545598397 506701309 277400987 633623772 703083605 815923782 512555570 6845219...
output:
3974026736738603400578723
result:
ok single line: '3974026736738603400578723'
Test #20:
score: 5
Accepted
time: 142ms
memory: 30496kb
input:
4000 999649683 293143786 404089543 948645960 591213944 420128767 913693955 904637197 90800310 285150476 40950603 561661321 824213238 245828843 95056861 901351197 260851255 529952933 567089905 577858555 278276783 867308618 151221118 542207472 381126520 757554818 581601842 978757967 34224053 402078118...
output:
3972590869295078207458903
result:
ok single line: '3972590869295078207458903'
Test #21:
score: 5
Accepted
time: 133ms
memory: 32528kb
input:
4000 999218074 322817 448108 1286850 1517907 1751394 1933727 1969357 1970595 2180924 2228253 2813059 2819753 2858829 2969167 2991999 3018423 3440367 3644635 3745672 4007786 4030391 4217008 4419577 4425316 4434695 4710215 4740192 5029585 5051326 5197090 5216976 5344821 5757139 5870299 5907179 6286242...
output:
2659476620951389455115559
result:
ok single line: '2659476620951389455115559'
Test #22:
score: 5
Accepted
time: 139ms
memory: 30424kb
input:
4000 999981742 999981642 999695393 999576758 998588017 998141300 997821833 997412364 996967360 996626793 996586318 996507782 996270534 996194469 995965073 995351707 995274486 995102954 994858106 994809057 994205121 993397640 993370901 993229088 992832981 992647741 991702382 991607766 991482261 99135...
output:
2661497262129514677449083
result:
ok single line: '2661497262129514677449083'
Test #23:
score: 5
Accepted
time: 130ms
memory: 32628kb
input:
4000 999998958 80298119 639623534 252373841 252373841 608720231 484025037 942468624 903920599 451221576 188477857 440570903 237556588 80298119 193335644 696786290 639623534 252373841 183942572 788156619 788156619 188397915 203318773 55628357 223723934 188477857 463664308 80298119 696786290 34175503 ...
output:
3860241287673882783928813
result:
ok single line: '3860241287673882783928813'
Test #24:
score: 5
Accepted
time: 130ms
memory: 30496kb
input:
4000 999947196 214942340 464409068 109365821 464921377 214993245 465607259 56260965 465620386 215230440 465885744 109490186 465940347 215301695 465991711 27981930 466373867 215602198 466493112 109789662 467266751 215686242 467670762 56325714 467840457 215712437 467925361 110074398 468260419 21594999...
output:
3392374041798690694758388
result:
ok single line: '3392374041798690694758388'
Test #25:
score: 5
Accepted
time: 132ms
memory: 34592kb
input:
4000 999999487 218682572 490886474 106276872 491038599 219062294 491785864 52115263 491844714 219234571 492390769 106436098 492590218 219475533 493221333 27006922 493446981 219607721 493480680 106511961 493595231 219918468 493679774 52477644 493748411 219937062 493890295 106590281 493897494 22080828...
output:
3404899865741070334696090
result:
ok single line: '3404899865741070334696090'
Test #26:
score: 5
Accepted
time: 132ms
memory: 30572kb
input:
4000 999870525 217442425 477510224 106411508 477897702 217857300 478055519 53847707 478223762 218453183 478530742 106606463 479257650 219043641 479372241 27806875 479563483 219101462 479747067 107088825 479769420 219261547 480193067 53870525 480275186 219453795 480459697 107565396 481178742 21952370...
output:
3398492240577479556055359
result:
ok single line: '3398492240577479556055359'
Test #27:
score: 5
Accepted
time: 136ms
memory: 30568kb
input:
4000 999883955 729352274 461616143 866927797 461561189 729126408 461504230 933802293 461276976 728847649 461137600 866127851 461060925 728573581 461055654 965971255 461007013 728544812 460447099 866048510 460215816 728280963 460090715 933186083 459641714 728063215 459566415 866010625 459427713 72776...
output:
3461503156788610927181394
result:
ok single line: '3461503156788610927181394'
Test #28:
score: 5
Accepted
time: 133ms
memory: 32536kb
input:
4000 999836657 726830261 437428117 864291876 437323121 726389365 436458491 929883217 436151067 726372382 436006434 863853298 435889116 726112171 435354528 959868001 435028691 725992398 434401003 863845895 433804894 725960900 432689843 929715566 432556191 725825927 432181732 862812972 432118481 72538...
output:
3470328507514617180628041
result:
ok single line: '3470328507514617180628041'
Test #29:
score: 5
Accepted
time: 133ms
memory: 32472kb
input:
4000 999709272 728347937 454004519 860864229 453924255 728304682 453916739 931339376 453578314 727171596 453474157 860846212 453070751 727104606 452793137 967850158 452643321 726707831 452573104 860480356 452143802 726689292 452074495 931046885 452001062 726167880 451665383 860026196 451328684 72564...
output:
3459828322351305394151676
result:
ok single line: '3459828322351305394151676'
Test #30:
score: 5
Accepted
time: 159ms
memory: 30512kb
input:
4000 999983168 212171530 317645701 896420454 999983068 927873123 820697889 226091734 339988907 451707831 859400977 940847121 759591226 230435743 587395309 145084943 243699242 137076914 419528394 68029220 329940970 36749752 918563727 667086543 715080242 694075052 521593064 936248720 693562834 3012614...
output:
3975167381683625168594671
result:
ok single line: '3975167381683625168594671'
Subtask #3:
score: 0
Time Limit Exceeded
Test #31:
score: 0
Time Limit Exceeded
input:
1000000 2 2 1 1 1 2 2 2 2 2 2 2 1 2 2 1 1 1 2 2 2 2 1 2 2 1 2 1 2 1 2 1 1 2 2 2 2 1 2 2 1 1 1 1 1 2 1 1 2 1 1 1 1 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 1 1 2 1 1 1 2 1 1 1 2 2 2 2 2 2 1 1 2 1 1 2 2 2 2 2 1 1 2 1 1 1 2 1 1 2 1 1 1 2 2 2 2 1 1 1 2 1 1 1 2 2 2 2 1 2 2 1 2 1 2 2 2 1 1 2 2 1 1 2 2 1 1 1 1 1 2 ...
output:
result:
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Time Limit Exceeded
Test #41:
score: 0
Time Limit Exceeded
input:
500000 999997472 323565887 829841159 316294741 207123786 197822285 87425904 283234947 457350978 346818392 59983222 782455248 784568068 729477373 116544863 669509195 402486856 202576480 122339471 760623311 842345622 481616662 856729905 50173442 129883284 52084768 196396910 320675364 895095006 6623157...
output:
result:
Subtask #6:
score: 0
Time Limit Exceeded
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Test #46:
score: 0
Time Limit Exceeded
input:
100000 999993517 598790459 537183965 68335700 591512847 918579772 779728634 48635238 740788103 407135955 819858816 563534822 567426511 517675399 559397183 296013105 923989546 259659935 728984034 189521707 829247701 283361594 213446040 199487702 371296223 366945332 121551756 10042853 341828937 107625...
output:
result:
Subtask #7:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
0%