QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#176870 | #5459. Goose, goose, DUCK? | lzqy_# | AC ✓ | 2087ms | 147688kb | C++14 | 2.2kb | 2023-09-12 09:06:23 | 2023-09-12 09:06:23 |
Judging History
answer
#include<bits/stdc++.h>
#define mp make_pair
#define ll long long
#define il inline
using namespace std;
const int maxn=1000010;
const int MAXN=maxn<<2;
il int read(){
int x=0;
char c=getchar();
for(;!(c>='0'&&c<='9');c=getchar());
for(;c>='0'&&c<='9';c=getchar())
x=(x<<1)+(x<<3)+c-'0';
return x;
}
struct info{
int xl,xr,yl,yr;
}a[maxn];
bool cmp1(info a,info b){return a.xl<b.xl;}
int n,k,m,M,c[maxn];
vector<int>v[maxn];
int dm[MAXN],ds[MAXN],lz[MAXN];
ll ans;
set<pair<int,pair<int,int> > >s;
void update(int i){
if(dm[i<<1]<dm[i<<1|1])
dm[i]=dm[i<<1],ds[i]=ds[i<<1];
else if(dm[i<<1]>dm[i<<1|1])
dm[i]=dm[i<<1|1],ds[i]=ds[i<<1|1];
else dm[i]=dm[i<<1],ds[i]=ds[i<<1]+ds[i<<1|1];
}
void pushdown(int i){
if(lz[i]){
dm[i<<1]+=lz[i],lz[i<<1]+=lz[i];
dm[i<<1|1]+=lz[i],lz[i<<1|1]+=lz[i];
}lz[i]=0;
}
void build(int i,int l,int r){
if(l==r){
ds[i]=1;
return ;
}int mid=l+r>>1;
build(i<<1,l,mid);
build(i<<1|1,mid+1,r);
update(i);
}
void Add(int i,int l,int r,int L,int R,int x){
// if(i==1) printf("Add->[%d,%d](%d)\n",L,R,x);
if(l>=L&&r<=R){
dm[i]+=x,lz[i]+=x;
return ;
}int mid=l+r>>1;
pushdown(i);
if(mid>=L) Add(i<<1,l,mid,L,R,x);
if(mid<R) Add(i<<1|1,mid+1,r,L,R,x);
update(i);
}
int main(){
n=read(),k=read();
for(int i=1;i<=n;i++){
c[i]=read();
if(v[c[i]].empty()) v[c[i]].push_back(0);
v[c[i]].push_back(i),M=max(M,c[i]);
}
for(int i=1;i<=M;i++) v[i].push_back(n+1);
for(int i=1;i<=M;i++)
for(int j=1;j<(int)v[i].size()-k;j++){
++m;
a[m].xl=v[i][j-1]+1,a[m].xr=v[i][j];
a[m].yl=v[i][j+k-1],a[m].yr=v[i][j+k]-1;
}
sort(a+1,a+1+m,cmp1);
//for(int i=1;i<=m;i++)
// printf("[%d,%d][%d,%d]\n",a[i].xl,a[i].xr,a[i].yl,a[i].yr);
ans=1ll*n*(n+1)/2;
build(1,1,n);
for(int i=1,j=1;i<=n;i++){
while(j<=m&&a[j].xl<=i){
s.insert(mp(a[j].xr,mp(a[j].yl,a[j].yr)));
Add(1,1,n,a[j].yl,a[j].yr,1),j++;
}
while(!s.empty()&&s.begin()->first<i){
Add(1,1,n,s.begin()->second.first,s.begin()->second.second,-1);
s.erase(s.begin());
}
// printf("%d,%d\n",dm[1],ds[1]);
if(dm[1]) ans-=n;
else ans-=n-ds[1];
}
printf("%lld\n",ans);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 4ms
memory: 34392kb
input:
6 2 1 2 2 1 3 3
output:
10
result:
ok 1 number(s): "10"
Test #2:
score: 0
Accepted
time: 4ms
memory: 32292kb
input:
6 1 1 2 3 4 5 6
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 30ms
memory: 65300kb
input:
100 10 142826 764475 142826 986320 764475 142826 142826 986320 764475 986320 764475 764475 764475 142826 142826 986320 764475 986320 764475 764475 142826 764475 142826 764475 986320 986320 764475 142826 764475 764475 142826 764475 764475 986320 142826 142826 142826 142826 764475 986320 986320 764475...
output:
4309
result:
ok 1 number(s): "4309"
Test #4:
score: 0
Accepted
time: 19ms
memory: 54956kb
input:
1000 100 144044 144044 606320 144044 144044 653289 606320 606320 606320 144044 653289 606320 144044 606320 144044 653289 606320 653289 144044 144044 606320 606320 606320 144044 606320 653289 653289 144044 606320 606320 606320 606320 606320 606320 606320 606320 653289 606320 653289 606320 653289 6532...
output:
494331
result:
ok 1 number(s): "494331"
Test #5:
score: 0
Accepted
time: 25ms
memory: 65152kb
input:
1000 2 37158 712133 695735 352502 37158 111876 979836 322207 850 170255 712133 37158 68113 170255 269273 322207 644692 127744 575843 269273 352502 68113 166126 413274 111876 575843 704107 695735 37158 604776 127744 269273 166126 704107 850 111876 352502 979836 850 850 712133 850 979836 575843 704107...
output:
382010
result:
ok 1 number(s): "382010"
Test #6:
score: 0
Accepted
time: 26ms
memory: 61600kb
input:
1000 1 439144 11249 309118 842057 842057 938195 823723 842057 589439 914850 938195 455713 91595 938195 553566 761181 553566 70966 455713 439144 704849 11249 11249 236580 320993 933831 872377 589439 435476 558991 914850 690853 482410 690853 715546 155003 435476 155003 435476 435476 842057 236580 7096...
output:
341042
result:
ok 1 number(s): "341042"
Test #7:
score: 0
Accepted
time: 28ms
memory: 65852kb
input:
1000 1 675227 756097 647871 465683 473815 162625 396802 61313 758469 968915 283015 326083 86904 672294 145904 621859 346020 237440 669779 282692 626616 722910 999031 141389 440533 971280 807058 346648 405103 669779 463968 214284 50833 661085 826455 991362 984243 704592 426668 998421 949882 147122 72...
output:
1
result:
ok 1 number(s): "1"
Test #8:
score: 0
Accepted
time: 2087ms
memory: 147688kb
input:
1000000 1 420242 544222 171447 777913 987553 724009 569564 35971 931705 898245 672004 267555 967920 126950 627536 979230 592634 345070 437097 838283 124796 525563 988560 362647 502828 510728 538451 742569 327219 207978 943947 684879 278534 669721 356340 258535 85663 265714 956295 291196 419333 19692...
output:
0
result:
ok 1 number(s): "0"
Test #9:
score: 0
Accepted
time: 658ms
memory: 109672kb
input:
1000000 1 559660 917135 718911 137428 227265 619698 582978 634509 968207 398589 647945 907790 647945 453872 267596 39233 647945 225421 404411 559660 401213 907790 765663 401213 339252 723380 907790 619698 896672 907790 58034 686103 455430 917135 686103 225421 619698 203386 893988 438096 75622 401213...
output:
499686064890
result:
ok 1 number(s): "499686064890"
Test #10:
score: 0
Accepted
time: 719ms
memory: 110448kb
input:
1000000 20 861642 606482 953312 90817 363428 948603 487519 232986 519567 387790 428832 519567 307633 737110 521903 537123 787533 232986 5583 363428 162408 90817 179560 859355 774243 861642 776916 206258 801420 519567 801420 422101 206258 787533 390434 62305 994340 741875 801420 138248 519567 531603 ...
output:
499129896013
result:
ok 1 number(s): "499129896013"
Test #11:
score: 0
Accepted
time: 668ms
memory: 110052kb
input:
1000000 200 485566 524102 778359 799174 823706 763480 616196 623850 594064 472722 778359 759395 336774 823706 814350 623850 662712 209130 702939 493199 974047 941295 623850 472722 947166 336774 493199 371798 974047 632804 702939 724695 509242 662712 776785 411318 280490 759395 336774 89517 493199 30...
output:
498381370313
result:
ok 1 number(s): "498381370313"
Test #12:
score: 0
Accepted
time: 521ms
memory: 104440kb
input:
1000000 2000 278305 278305 348110 113854 832030 667125 113854 821689 667125 481645 305363 481645 348110 481645 278305 123360 821689 348110 481645 305363 305363 832030 123360 821689 832030 481645 113854 123360 832030 541509 278305 832030 541509 113854 481645 278305 113854 481645 305363 348110 278305 ...
output:
499905050517
result:
ok 1 number(s): "499905050517"
Test #13:
score: 0
Accepted
time: 618ms
memory: 110928kb
input:
1000000 1 20506 24350 30587 37027 42391 66414 97104 110890 139464 147153 151865 154652 163381 181574 232570 237490 262035 270050 287512 300416 308447 310125 310983 312781 317123 318837 328920 330480 344807 346415 348094 350611 356439 366128 374463 383635 386897 408221 415742 416461 417999 419807 425...
output:
499801321042
result:
ok 1 number(s): "499801321042"
Test #14:
score: 0
Accepted
time: 608ms
memory: 112344kb
input:
1000000 3 11023 31773 32161 38871 41021 44852 48136 50602 53388 101255 102564 106529 107369 122558 127492 129008 139504 168813 175401 197384 227294 235164 240779 260845 274861 280036 294860 328235 353725 355819 364809 368636 371245 380336 385635 387362 387463 397455 399364 401758 407996 424116 42811...
output:
499800994499
result:
ok 1 number(s): "499800994499"
Test #15:
score: 0
Accepted
time: 603ms
memory: 111780kb
input:
1000000 20 3503 16481 16795 23406 31913 41872 51334 54530 54659 58868 61041 88488 93579 109541 110340 128839 131239 134456 158540 178156 181454 198922 200083 203463 220228 224053 260400 262942 280472 285105 287261 318193 338271 345198 355790 359916 372574 374790 380392 391766 416424 418976 424552 42...
output:
499797927548
result:
ok 1 number(s): "499797927548"
Test #16:
score: 0
Accepted
time: 580ms
memory: 112112kb
input:
1000000 100 26705 33485 50901 54941 68943 81029 85286 113183 123732 125867 126194 135433 178979 180530 192244 193156 208961 212468 217679 227986 240063 252514 254933 257638 257813 261582 271371 292677 298888 319760 321433 327241 345967 347806 360472 369382 385741 390248 396342 405013 405299 411923 4...
output:
499785153218
result:
ok 1 number(s): "499785153218"
Test #17:
score: 0
Accepted
time: 552ms
memory: 110396kb
input:
1000000 1000 54734 56859 60900 69121 73309 75054 98086 124241 128326 130579 133938 138638 170907 174090 209593 210626 227131 240148 285324 294171 294911 306676 310066 315911 316415 323391 325543 335382 338701 356893 357975 361369 375642 393131 412064 424646 429594 433991 441381 448701 450511 478719 ...
output:
499711049085
result:
ok 1 number(s): "499711049085"
Test #18:
score: 0
Accepted
time: 47ms
memory: 87352kb
input:
1000000 10000 15780 26236 27684 29851 30391 70638 74718 105424 106626 112856 121360 136256 143306 144423 160215 172628 178833 187008 187580 193012 204251 249462 268531 307132 312751 317920 334377 334794 338564 346157 346869 361652 385944 418212 419616 431221 452685 453777 457638 457725 499400 508745...
output:
500000494950
result:
ok 1 number(s): "500000494950"
Test #19:
score: 0
Accepted
time: 648ms
memory: 111036kb
input:
1000000 3 13192 25254 37301 53898 55107 56589 60875 62479 90808 108918 112707 135312 138180 140042 144199 146700 148639 159639 161015 182707 203339 205293 217104 217993 221972 233487 256690 279730 303295 315509 323466 324495 343702 348772 362594 552837 376486 381055 388704 399808 401931 422683 43256...
output:
499724407843
result:
ok 1 number(s): "499724407843"
Test #20:
score: 0
Accepted
time: 673ms
memory: 112756kb
input:
1000000 20 31594 44498 46841 50016 54025 62603 67202 69488 70166 115334 144272 148075 153366 157675 165752 175136 182730 201633 206707 212924 226032 245422 258994 270652 317043 338717 338753 339996 345085 346180 359946 367730 371425 376731 407733 409245 410195 416008 431461 439720 442584 444716 4468...
output:
499596476425
result:
ok 1 number(s): "499596476425"
Test #21:
score: 0
Accepted
time: 703ms
memory: 110788kb
input:
1000000 100 57157 111627 122547 135685 140722 142818 153374 209026 223146 239026 252837 256776 281064 289700 290219 292233 294024 349159 355923 361093 362183 378753 381072 389411 391472 391617 396151 397557 398169 428876 432451 435010 449056 449146 451048 460835 462298 474684 482179 482770 488686 49...
output:
499391962641
result:
ok 1 number(s): "499391962641"
Test #22:
score: 0
Accepted
time: 682ms
memory: 110016kb
input:
1000000 1000 31493 41881 47733 61011 71910 80336 95923 110457 110595 120368 127883 129274 173259 176814 195869 210362 221085 239440 255462 257568 259584 285984 290476 297671 313610 334878 338145 362300 365380 367825 380147 392530 394324 395227 406251 406263 418868 432138 437741 438162 486778 512830 ...
output:
498783493376
result:
ok 1 number(s): "498783493376"
Test #23:
score: 0
Accepted
time: 49ms
memory: 86068kb
input:
1000000 10000 42038 50384 66576 86923 87920 89011 112787 113849 124259 126873 129621 137006 139874 157994 325776 166583 186258 198164 209632 210915 211671 214969 216668 217801 237103 239515 249705 268737 281178 294292 319964 325776 340804 352085 354292 363407 388690 392733 393593 397954 405187 41300...
output:
500000487674
result:
ok 1 number(s): "500000487674"
Test #24:
score: 0
Accepted
time: 790ms
memory: 110980kb
input:
1000000 20 8297 10253 11655 35181 469963 40980 44610 45480 45968 144412 349288 110821 793614 35181 141187 44610 144412 147994 162380 163126 8297 715077 223055 227282 239159 255415 256199 270255 793614 393755 286243 296085 307696 864863 322214 326864 328862 594408 673065 386853 393755 937498 412435 4...
output:
498372290400
result:
ok 1 number(s): "498372290400"
Test #25:
score: 0
Accepted
time: 771ms
memory: 110892kb
input:
1000000 100 486435 23761 24235 33864 40684 53396 57584 295737 896419 77583 583583 548385 493160 791063 144501 486435 170285 174686 187914 77583 199976 209866 221143 222079 231963 975385 245272 246644 252021 295737 296906 313568 324144 334442 343938 349704 368668 421176 805941 919799 382762 812603 42...
output:
496980423237
result:
ok 1 number(s): "496980423237"
Test #26:
score: 0
Accepted
time: 686ms
memory: 109504kb
input:
1000000 1000 2145 68136 16607 409458 22354 61633 68136 68812 69932 84624 202591 96813 99616 101201 123924 709687 140217 146803 149628 154171 173873 181288 202591 203691 433640 181288 260177 260255 262688 417949 285610 296625 316727 329114 332321 781226 790225 950078 409458 399598 272557 412138 41794...
output:
494633760441
result:
ok 1 number(s): "494633760441"
Test #27:
score: 0
Accepted
time: 44ms
memory: 83592kb
input:
1000000 10000 17351 65877 101842 108439 130529 131763 144871 835489 175925 184547 716087 237095 248755 263575 824662 274206 278167 371885 698029 971833 308720 315483 184547 441863 274206 354454 587577 366009 366344 315483 367916 371750 711360 371750 402253 403715 404490 412144 434109 441863 810118 4...
output:
500000435543
result:
ok 1 number(s): "500000435543"
Test #28:
score: 0
Accepted
time: 775ms
memory: 112308kb
input:
1000000 20 126110 52385 464710 203919 305450 214423 566044 926946 477145 125830 602550 854825 699058 360960 662325 385240 252572 166915 585008 749718 385240 801236 385240 956433 101385 854825 626672 313521 755479 385240 227584 931898 214423 723758 610608 101385 124880 380048 699058 723758 876575 809...
output:
497932776583
result:
ok 1 number(s): "497932776583"
Test #29:
score: 0
Accepted
time: 773ms
memory: 112880kb
input:
1000000 100 534859 762067 163543 126964 605251 944335 407972 651389 555665 447742 932806 101606 552259 784295 729406 460940 101606 295842 677547 330769 166607 585701 534859 605251 71349 740213 71349 709084 932806 967932 702200 476270 740213 236337 192428 884658 265499 884658 526560 27215 784295 5348...
output:
496316167265
result:
ok 1 number(s): "496316167265"
Test #30:
score: 0
Accepted
time: 679ms
memory: 109540kb
input:
1000000 1000 762444 693573 2802 446818 560172 492832 383822 348558 527640 88414 640787 16618 719592 714819 645316 978131 878247 666414 692106 653890 403061 645316 16618 957721 640654 809285 240678 148559 315034 150418 383822 955234 595812 714819 333549 129451 958145 333549 422540 721509 139762 51676...
output:
494073094584
result:
ok 1 number(s): "494073094584"
Test #31:
score: 0
Accepted
time: 58ms
memory: 84320kb
input:
1000000 10000 698698 886860 655713 894253 100787 686560 716963 105439 783355 784550 8867 698748 541374 365425 49544 783355 112893 596451 515736 445994 515736 194834 596451 137179 894253 348902 515736 209077 698698 445994 230073 110676 235382 698748 87090 787660 596451 594676 938008 327825 483894 923...
output:
500000385825
result:
ok 1 number(s): "500000385825"
Test #32:
score: 0
Accepted
time: 1053ms
memory: 109216kb
input:
1000000 20 923555 989327 140006 149591 154990 770656 408196 595470 474964 537512 108725 16804 179424 723202 299438 427345 153899 332593 919096 234140 554147 754591 426981 640533 138648 838016 395769 701080 444832 776741 144383 602791 344245 178826 617846 276478 281857 670811 182691 876433 89178 1479...
output:
269690150257
result:
ok 1 number(s): "269690150257"
Test #33:
score: 0
Accepted
time: 91ms
memory: 86672kb
input:
1000000 100 894270 701908 348954 29652 46340 7063 218477 942940 128381 502610 965560 831423 440699 564774 550341 990435 852728 397056 625626 506722 608789 551661 828038 357426 842129 239594 347344 536072 940920 913148 87633 180898 670133 473898 500412 890328 196048 945189 695112 11699 368848 217761 ...
output:
495835073299
result:
ok 1 number(s): "495835073299"
Test #34:
score: 0
Accepted
time: 77ms
memory: 84020kb
input:
1000000 1000 146876 535949 746095 349132 639639 361106 286826 779672 175664 75072 511080 451425 511080 867604 802041 924874 223977 90568 525070 953756 85401 434559 380849 375687 483043 441018 90151 649468 624535 342124 886732 351402 99960 31304 403208 821589 808175 938946 827916 887938 802147 612931...
output:
500000500000
result:
ok 1 number(s): "500000500000"
Test #35:
score: 0
Accepted
time: 72ms
memory: 83784kb
input:
1000000 10000 841599 361404 145028 675800 199807 127899 37744 367759 570994 648968 893252 737006 913180 722495 537159 881248 984071 189205 436546 168541 726657 867566 515981 5265 248098 913968 512096 604631 5811 205062 672411 949351 590675 497055 415061 113883 333423 123673 709782 325626 377937 7754...
output:
500000500000
result:
ok 1 number(s): "500000500000"
Test #36:
score: 0
Accepted
time: 439ms
memory: 109000kb
input:
1000000 20 51324 985511 51324 51324 51324 985511 51324 985511 417669 985511 985511 985511 51324 417669 417669 51324 985511 417669 51324 985511 417669 51324 417669 417669 51324 51324 51324 985511 51324 985511 51324 51324 985511 985511 985511 417669 417669 985511 51324 417669 985511 51324 51324 985511...
output:
499992045370
result:
ok 1 number(s): "499992045370"
Test #37:
score: 0
Accepted
time: 452ms
memory: 100972kb
input:
1000000 100 107702 476057 476057 476057 718986 476057 476057 107702 476057 718986 718986 718986 476057 476057 107702 107702 718986 476057 718986 718986 107702 718986 718986 718986 476057 718986 718986 718986 718986 718986 476057 107702 107702 476057 476057 476057 718986 476057 718986 107702 718986 4...
output:
499991755386
result:
ok 1 number(s): "499991755386"
Test #38:
score: 0
Accepted
time: 460ms
memory: 109704kb
input:
1000000 1000 958601 116914 116914 589550 116914 116914 958601 116914 958601 958601 116914 958601 589550 589550 116914 116914 116914 958601 589550 589550 116914 589550 116914 958601 116914 958601 589550 116914 958601 958601 958601 116914 116914 589550 958601 589550 589550 958601 958601 958601 116914 ...
output:
499991601479
result:
ok 1 number(s): "499991601479"
Test #39:
score: 0
Accepted
time: 446ms
memory: 102376kb
input:
1000000 10000 644458 767484 108648 108648 767484 644458 644458 767484 644458 644458 644458 767484 644458 644458 644458 644458 767484 644458 644458 644458 767484 108648 644458 644458 767484 108648 644458 108648 767484 644458 767484 644458 767484 108648 108648 767484 767484 644458 767484 767484 108648...
output:
499991785725
result:
ok 1 number(s): "499991785725"
Test #40:
score: 0
Accepted
time: 882ms
memory: 106972kb
input:
1000000 20 873002 450018 9888 248507 871070 300540 930269 465089 444632 9849 447875 386365 128305 895779 338602 769999 404169 998443 390426 989636 301758 481590 77748 753136 178402 73801 393865 332805 583013 546729 192898 596395 889967 743660 367511 365075 364656 822566 799880 28755 351614 389257 42...
output:
196659308951
result:
ok 1 number(s): "196659308951"
Test #41:
score: 0
Accepted
time: 1241ms
memory: 111256kb
input:
1000000 5 538693 776730 502024 413243 531707 11748 874778 720721 931056 235187 638366 463275 33691 233860 907251 290853 553006 504147 472583 168639 565616 356969 266190 821242 921105 89941 512363 992441 599518 768575 10656 322949 540275 104250 120821 484205 121784 73343 412438 171545 503940 643023 8...
output:
215757902963
result:
ok 1 number(s): "215757902963"
Test #42:
score: 0
Accepted
time: 1262ms
memory: 111736kb
input:
1000000 4 507660 309195 797944 138623 929921 297375 436242 16211 135484 958984 945634 885574 314555 210408 729866 57905 412659 328477 994684 593088 936867 249051 694497 221 18227 940327 428876 254887 838346 13651 468580 500022 226494 906990 132614 321987 653063 152458 474371 843963 616529 31024 5067...
output:
228016732045
result:
ok 1 number(s): "228016732045"
Test #43:
score: 0
Accepted
time: 1259ms
memory: 111744kb
input:
1000000 3 325831 521999 423880 205039 168231 863017 127350 673246 520684 782822 696799 16621 840222 383403 471580 594846 187613 894664 331157 33695 794732 579060 957571 281087 300714 879144 345990 123881 131366 123715 602567 615436 462256 861488 884404 64761 336231 412369 354792 219015 989201 739810...
output:
245821846717
result:
ok 1 number(s): "245821846717"