QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#50395 | #2371. Max or Min | sjcx | AC ✓ | 352ms | 33840kb | C++14 | 2.3kb | 2022-09-25 20:21:44 | 2022-09-25 20:21:45 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<vector>
using namespace std;
#define re int
inline int read(){
int x=0,ff=1;char c=getchar();
while(c<'0'||c>'9'){if(c=='-')ff=-1;c=getchar();}
while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c^'0');c=getchar();}
return x*ff;
}
#define lz (i<<1)
#define rz (i<<1|1)
#define mid ((l+r)>>1)
int n,m,f[1600005],lt[1600005],rt[16000005],ls[16000005],rs[16000005];
vector<int>qwq[200005];
bool tuu[1600005];
inline void push_up(int i){
lt[i]=lt[lz];rt[i]=rt[rz];
ls[i]=ls[lz];rs[i]=rs[rz];
f[i]=f[lz]+f[rz]+((lt[rz]!=rt[lz])?((ls[rz]+rs[lz])/2-ls[rz]/2-rs[lz]/2):0);
tuu[i]=(tuu[lz]&tuu[rz])&(lt[rz]!=rt[lz]);
if(lt[rz]!=rt[lz]){
if(tuu[lz])ls[i]=ls[i]+ls[rz];
if(tuu[rz])rs[i]=rs[i]+rs[lz];
}
}
void build(int i,int l,int r){
if(l==r){tuu[i]=1;
f[i]=0;ls[i]=rs[i]=1;return;
}
build(lz,l,mid);build(rz,mid+1,r);
push_up(i);
}
void update(int i,int l,int r,int x){
if(l==r){
f[i]=0;lt[i]=rt[i]=1;ls[i]=rs[i]=1;return;
}
if(mid>=x)update(lz,l,mid,x);
else update(rz,mid+1,r,x);
push_up(i);
}
int ss,la,kk;
void query(int i,int l,int r,int x,int y){
if(x<=l&&r<=y){
ss+=f[i];
//cout<<l<<" "<<r<<" "<<x<<" "<<y<<" "<<f[i]<<" "<<ss<<" "<<kk<<" "<<ls[i]<<" "<<rs[i]<<" "<<lt[i]<<" "<<la<<endl;
if(la!=-1){
ss+=((la!=lt[i])?(ls[i]+kk)/2-ls[i]/2-kk/2:0);
}
if(!tuu[i]||lt[i]==la)kk=rs[i];
else kk+=rs[i];
//cout<<kk<<" "<<rs[i]<<" "<<lt[i]<<" "<<la<<endl;
la=rt[i];return;
}
if(mid>=x)query(lz,l,mid,x,y);
if(mid<y)query(rz,mid+1,r,x,y);
}
int main(){
n=read();m=read();int x;int N=n<<1;
for(re i=1;i<=n;i++){
x=read();qwq[x].emplace_back(i);
}
build(1,1,N);
for(re i=1;i<=m;i++){
int u=qwq[i].size(),ans=0;
if(!u){
printf("-1 ");continue;
}
for(re j=0;j<u-1;j++){
la=-1;ss=0;kk=0;
if(qwq[i][j]+1<qwq[i][j+1]){
query(1,1,N,qwq[i][j]+1,qwq[i][j+1]-1);
}
//cout<<i<<" "<<j<<" "<<qwq[i][j]+1<<" "<<qwq[i][j+1]-1<<" "<<ss<<endl;
ans+=ss;
}
ss=0;la=-1;kk=0;
if(qwq[i][0]+n-1>=qwq[i][u-1]+1){
query(1,1,N,qwq[i][u-1]+1,qwq[i][0]+n-1);
}
ans+=ss;
printf("%d ",ans+n-u);
//cout<<i<<" "<<ans<<endl;
for(re j:qwq[i]){
update(1,1,N,j);update(1,1,N,j+n);
}
}puts("");
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 8364kb
input:
7 5 2 5 1 1 2 3 2
output:
5 5 7 -1 6
result:
ok single line: '5 5 7 -1 6 '
Test #2:
score: 0
Accepted
time: 6ms
memory: 8504kb
input:
1000 1000 89 983 751 38 201 34 39 841 873 453 65 674 216 560 644 914 345 670 518 622 938 583 719 137 78 359 860 448 907 741 629 236 549 893 999 844 345 63 66 320 723 990 467 215 24 665 756 682 604 853 160 262 30 153 31 278 631 232 360 495 519 347 906 259 992 541 33 167 233 661 720 908 332 55 153 17 ...
output:
999 1000 1001 -1 -1 -1 -1 1002 -1 1002 -1 -1 -1 1005 1006 1005 1010 -1 1011 1011 1014 1013 1018 1018 -1 1020 1023 1024 1025 1025 1028 1029 1029 1031 -1 1031 1038 1038 1039 1043 -1 1046 -1 1047 1046 -1 -1 1051 1052 -1 1053 1053 1056 1056 1059 -1 1059 1062 1063 1064 1065 1066 1065 -1 1070 1068 1074 -1...
result:
ok single line: '999 1000 1001 -1 -1 -1 -1 1002... 1004 1003 1000 1000 -1 999 -1 '
Test #3:
score: 0
Accepted
time: 4ms
memory: 8460kb
input:
1000 100 43 45 96 56 7 92 80 59 9 93 53 28 34 71 89 5 12 51 8 29 32 28 74 41 23 96 4 59 6 72 6 98 26 4 79 48 89 65 35 53 35 66 24 63 53 100 22 97 1 25 12 82 44 60 29 88 67 95 7 63 59 84 11 58 78 61 99 10 11 21 38 42 89 60 68 24 13 26 76 6 11 85 72 94 21 3 20 42 64 13 87 61 57 98 21 13 25 33 31 78 6 ...
output:
987 1006 1008 1022 1034 1038 1051 1065 1072 1075 1089 1104 1114 1125 1135 1143 1149 1153 1156 1175 1169 1197 1191 1213 1220 1224 1241 1242 1241 1254 1265 1266 1263 1284 1284 1296 1297 1301 1309 1304 1310 1304 1317 1312 1312 1318 1330 1319 1329 1326 1322 1321 1312 1322 1319 1316 1314 1311 1306 1301 1...
result:
ok single line: '987 1006 1008 1022 1034 1038 1...29 1029 1014 1013 1007 995 996 '
Test #4:
score: 0
Accepted
time: 2ms
memory: 8408kb
input:
1000 500 325 252 102 474 102 213 436 489 442 260 127 106 479 47 450 391 137 435 388 19 451 177 494 169 476 276 443 421 183 265 495 462 160 339 92 263 184 324 374 44 305 306 150 438 88 250 482 469 252 376 319 39 334 340 182 136 255 495 136 496 312 41 334 479 323 201 302 493 343 116 180 415 428 58 389...
output:
999 998 1000 1006 1008 1010 1012 1014 1015 -1 -1 -1 1018 1021 -1 1026 1026 1027 1027 1038 1038 1039 1043 -1 1042 -1 -1 1049 1052 1055 1059 -1 1060 -1 1064 1065 1069 1072 1073 1071 1075 1076 1085 1083 1090 -1 1088 1094 1096 1099 1099 1102 1102 -1 1104 -1 -1 1104 1110 1111 1110 1113 1118 1115 1124 112...
result:
ok single line: '999 998 1000 1006 1008 1010 10...13 1008 1004 1002 1003 998 999 '
Test #5:
score: 0
Accepted
time: 1ms
memory: 8500kb
input:
1000 10 10 3 1 1 3 4 9 5 7 7 9 4 1 8 9 5 6 1 1 4 7 9 10 2 2 4 1 4 10 6 9 7 6 5 4 9 4 8 4 1 5 5 10 9 5 7 1 1 5 7 2 9 8 1 3 8 9 8 1 6 1 10 7 10 6 1 9 6 6 2 5 3 8 9 1 10 2 2 6 10 6 2 7 6 5 5 2 4 9 1 4 1 7 7 1 10 1 8 6 2 1 9 4 3 9 7 8 7 1 5 9 2 2 5 4 10 9 2 1 2 2 1 5 10 4 5 4 4 10 9 1 10 10 10 3 5 8 1 8...
output:
900 992 1088 1145 1154 1179 1160 1091 997 885
result:
ok single line: '900 992 1088 1145 1154 1179 1160 1091 997 885 '
Test #6:
score: 0
Accepted
time: 351ms
memory: 33840kb
input:
200000 200000 197543 192033 68698 92316 101105 108314 167424 42287 198103 96873 181007 90054 44902 63014 39886 13121 100673 922 101400 163828 48349 72261 114526 119401 113604 103065 183011 154652 109138 126652 94974 30269 145851 94410 40539 199281 85891 36305 175226 125138 47940 79444 33199 37866 77...
output:
199999 199999 -1 -1 200002 -1 -1 -1 -1 -1 200002 200003 -1 200008 200008 200010 -1 -1 -1 -1 200013 200013 -1 200015 -1 -1 200017 200019 200019 -1 -1 200026 -1 200026 200027 200032 -1 200032 -1 -1 200035 200035 200038 200037 200042 -1 200043 -1 -1 200042 200046 200049 -1 -1 200050 200051 200052 20005...
result:
ok single line: '199999 199999 -1 -1 200002 -1 ...-1 200001 200001 200000 199999 '
Test #7:
score: 0
Accepted
time: 294ms
memory: 32056kb
input:
200000 50000 6878 2016 29769 20951 7730 13017 11557 11339 23360 36617 42213 17538 23137 10307 17149 8455 17204 4142 31349 49148 34041 42756 33064 38582 7 40949 42549 25068 46776 37825 26257 17515 49703 23378 14819 36949 43577 39680 47127 9501 32881 12474 12476 13276 10297 10852 49046 24368 13856 434...
output:
199996 200000 200002 200010 200011 200022 200025 200027 200033 200034 200037 200039 200042 200049 200050 200057 -1 200056 200063 200074 200074 200082 200088 200089 -1 200090 200098 200099 200099 200107 200111 200117 200114 200123 200130 200135 200130 200139 200138 200159 200157 200159 200167 200171 ...
result:
ok single line: '199996 200000 200002 200010 20...10 200007 200006 200000 199996 '
Test #8:
score: 0
Accepted
time: 259ms
memory: 31068kb
input:
200000 1000 742 757 35 143 108 805 363 252 338 550 348 93 235 183 387 475 269 267 742 466 722 609 612 709 272 284 987 944 330 427 720 701 940 858 147 200 266 544 56 371 26 983 950 611 437 456 564 433 866 156 423 153 76 195 694 166 687 889 495 76 302 548 598 877 912 216 901 557 927 219 54 406 768 441...
output:
199795 199999 200227 200388 200622 200767 200992 201205 201400 201601 201799 201993 202190 202372 202609 202815 202952 203180 203413 203603 203793 203949 204156 204341 204544 204744 204918 205141 205370 205584 205779 206017 206214 206391 206622 206809 207042 207278 207458 207643 207910 208071 208314...
result:
ok single line: '199795 199999 200227 200388 20...54 200408 200186 200014 199789 '
Test #9:
score: 0
Accepted
time: 309ms
memory: 32040kb
input:
199999 50000 45848 39915 40587 29978 46670 17368 6378 15261 29412 12861 2143 37548 44459 14145 22081 24137 7826 3822 36956 46072 495 38003 23840 48610 12941 19683 41376 40948 3768 40196 22773 2541 29635 22705 46329 3187 6658 31961 20572 31711 320 17053 35763 35900 7899 36693 10148 42364 44979 48972 ...
output:
199993 200000 200008 -1 200009 200014 200010 200018 200017 200033 200034 200038 200038 200043 200043 200049 200057 200063 200064 200065 200070 200075 200081 200082 200092 200094 200102 200107 200106 200114 200121 200128 200129 200136 200139 200139 200149 200149 200148 200161 -1 200168 200171 200171 ...
result:
ok single line: '199993 200000 200008 -1 200009...12 200001 200005 199998 199996 '
Test #10:
score: 0
Accepted
time: 307ms
memory: 31980kb
input:
200000 40000 13620 32538 10515 30686 15746 6325 4697 9861 2920 29577 32123 5297 30110 39686 19427 26705 9186 11389 17600 5563 36532 31077 19207 38373 13082 39192 15533 17901 3357 9043 1262 24083 3403 15673 30090 34170 36339 39569 1026 34090 4396 38020 24287 18001 33486 16608 8428 35901 10743 4375 19...
output:
199995 200000 200002 200012 200021 200021 200032 200031 200029 200043 200039 200051 200055 200054 200068 200068 200083 200083 200084 200082 200094 200099 200102 200103 200106 200113 200117 200128 200143 200144 200151 200153 200155 200163 200169 200170 200172 200174 200179 200182 200201 -1 200200 200...
result:
ok single line: '199995 200000 200002 200012 20...14 200013 200009 199997 199995 '
Test #11:
score: 0
Accepted
time: 344ms
memory: 32088kb
input:
200000 60000 31623 24198 24830 12432 43905 27005 38416 58226 52311 16360 45007 21267 54948 8224 31768 38718 57926 8383 9289 9630 40063 31331 26921 11494 14229 5809 59966 24938 26002 58096 5845 23652 4516 682 52253 14320 10814 2894 4716 53423 44470 26929 36473 44360 7109 45096 29664 44323 16970 59375...
output:
199995 200003 200004 200009 200006 200013 200016 200019 200023 200023 200025 200032 200038 200043 200047 200050 200050 200050 200054 200059 200059 200069 200072 200071 200075 200076 200081 200081 200083 200085 200087 200088 200092 200093 200098 200098 200099 200103 200106 200106 200102 200115 200119...
result:
ok single line: '199995 200003 200004 200009 20...08 200003 200001 199998 199999 '
Test #12:
score: 0
Accepted
time: 319ms
memory: 32248kb
input:
200000 70000 2177 17867 44084 21209 15888 30993 58380 32408 62751 46104 45098 23508 17975 50333 19490 56276 18648 41135 15742 37408 7572 23011 23482 7510 55746 37966 64278 30616 45228 41470 1240 47084 53921 58386 6983 4395 8052 43005 53521 1538 20251 18279 57365 48148 37024 66636 13386 45493 52788 3...
output:
199996 200002 200003 200005 200011 200013 -1 200012 200020 200023 200024 -1 200024 200027 200027 200029 200031 200032 200033 200042 200042 -1 200044 200045 -1 200047 200053 200054 200057 200061 200062 200066 200067 200070 -1 200074 200077 200077 200078 200082 200083 -1 200086 200090 200089 200097 20...
result:
ok single line: '199996 200002 200003 200005 20...002 -1 200003 199998 199999 -1 '
Test #13:
score: 0
Accepted
time: 343ms
memory: 32732kb
input:
200000 100000 87913 5444 74716 61102 73098 32247 87151 25896 99184 51569 63945 47358 81013 27075 84598 40574 85342 26648 93662 33292 87005 62651 87958 52741 76737 4163 73501 7772 82012 42389 68022 61902 93128 33015 90547 46956 75103 13626 71430 24236 82055 41529 91137 43936 63441 394 69776 38354 968...
output:
199998 199997 -1 200006 200007 200005 -1 200009 200014 200019 200020 200019 200022 200026 -1 200029 200030 200029 200034 200034 200037 -1 200036 200039 200043 200046 200046 200049 -1 200047 200053 200054 -1 200058 200061 200062 -1 -1 200063 200063 200060 200071 -1 -1 200075 200076 -1 200080 200080 -...
result:
ok single line: '199998 199997 -1 200006 200007...12 200005 199999 200003 199996 '
Test #14:
score: 0
Accepted
time: 270ms
memory: 31088kb
input:
200000 1000 134 735 344 878 25 934 443 639 241 727 56 599 463 766 494 949 184 698 245 597 69 888 171 996 369 588 307 811 403 970 326 924 482 871 36 821 442 722 213 853 557 697 47 753 348 878 45 727 314 864 389 643 421 747 540 808 273 949 529 919 397 894 434 855 186 813 45 951 184 762 422 992 248 742...
output:
199819 199990 200183 200387 200566 200717 200911 201085 201272 201485 201620 201806 201971 202161 202333 202501 202670 202807 202985 203120 203299 203434 203632 203810 203943 204116 204317 204528 204656 204875 205018 205201 205364 205569 205746 205884 206061 206281 206440 206588 206771 206966 207119...
result:
ok single line: '199819 199990 200183 200387 20...88 200427 200243 200008 199762 '
Test #15:
score: 0
Accepted
time: 146ms
memory: 30892kb
input:
200000 10 3 9 3 10 3 5 3 5 3 6 3 6 1 6 1 5 1 7 2 8 3 5 3 5 3 8 3 5 1 8 1 5 1 5 3 9 3 7 1 8 3 10 1 8 2 9 1 7 1 5 2 10 1 8 2 6 3 5 3 7 2 9 3 7 1 10 1 6 3 5 2 8 2 9 1 10 2 7 2 8 3 9 3 5 1 10 2 7 2 7 1 7 3 10 1 9 2 6 3 8 1 10 1 9 3 6 3 10 3 6 3 6 1 6 1 10 1 6 1 8 3 6 3 9 3 8 1 6 2 6 1 5 3 8 1 7 1 8 3 10...
output:
166823 199798 233113 299998 266564 249686 233356 216750 199923 183371
result:
ok single line: '166823 199798 233113 299998 26...86 233356 216750 199923 183371 '
Test #16:
score: 0
Accepted
time: 308ms
memory: 32028kb
input:
200000 50000 2554 34622 14488 34796 15306 43646 25610 47257 21624 34900 33947 39965 21288 42436 13427 40747 4609 42424 32752 45742 32124 37524 17840 39773 19335 37200 16174 44624 34212 39317 23793 34596 15072 36822 8787 37064 22427 41231 31629 36366 30130 38925 33946 46182 20297 39159 7310 37958 647...
output:
199993 200003 200006 200014 200015 -1 200018 200021 200024 200026 200033 200033 200033 200039 200042 200041 200044 200048 200050 200051 200054 200056 200063 200063 200065 200067 200065 200071 200076 -1 200085 200090 200097 200101 200101 200105 200109 -1 -1 200115 200117 200118 200122 200123 200128 2...
result:
ok single line: '199993 200003 200006 200014 20...14 200012 200003 200002 199994 '
Test #17:
score: 0
Accepted
time: 352ms
memory: 32004kb
input:
200000 60000 9461 51803 17967 28607 2886 31228 20040 52283 11588 33381 17712 58489 1507 28153 8588 47879 161 53841 16874 31159 21159 43382 19054 57090 3127 38476 19069 28129 16500 38359 2902 50100 13391 43766 12901 37168 5186 45249 6948 29159 10104 57369 1597 25014 11904 26353 16454 48705 11749 3881...
output:
199990 200005 200013 200010 200020 200026 200028 200025 200036 200037 200044 200046 200052 200051 200056 200059 200069 200074 200076 200078 200087 200088 200093 200097 200102 200111 200119 200121 200122 200124 200128 200129 200142 200139 200145 200148 200153 200160 200158 200165 200181 200179 200188...
result:
ok single line: '199990 200005 200013 200010 20...05 200006 200003 199999 199998 '
Test #18:
score: 0
Accepted
time: 316ms
memory: 32244kb
input:
200000 70000 35620 10336 38558 20345 46516 20250 33072 11137 40938 20071 58256 31368 37438 23387 58019 22575 56057 17249 63385 8143 35647 9240 36741 7832 46087 10889 43807 25430 64807 24879 61355 20297 54421 15830 37097 1237 46834 23261 68151 22620 63353 15910 51557 4299 67459 24679 63016 5509 64212...
output:
199999 200000 199997 200006 200002 200010 200013 200021 200022 200024 200029 200034 200033 200037 200039 200041 200039 200049 200051 200052 200056 200059 200059 200057 200065 200070 200071 200077 200082 200084 200088 200095 200090 200102 200103 -1 200104 200111 200113 200120 200114 200128 200130 200...
result:
ok single line: '199999 200000 199997 200006 20...09 200007 200003 200002 199996 '
Test #19:
score: 0
Accepted
time: 292ms
memory: 32052kb
input:
200000 50000 43676 8928 48526 22309 42063 15506 40131 2224 44275 22669 48370 6371 45196 30257 38701 6805 44132 8078 35956 32758 34838 16284 44482 19560 39751 8407 46842 26514 40907 30469 34209 16047 47630 24267 43216 14956 37886 23221 36009 17032 38878 20970 34104 1965 41172 21026 44423 1219 34464 6...
output:
199998 200001 199999 200004 200008 200011 200010 200014 200014 200020 200020 200025 200029 200027 200035 200042 200041 200044 200047 200049 200055 200056 200060 200062 200061 200068 200071 200073 200079 200077 200082 200092 200095 200100 200109 200104 200114 200121 200119 200125 200125 200131 200133...
result:
ok single line: '199998 200001 199999 200004 20...06 200008 200002 199998 199997 '
Test #20:
score: 0
Accepted
time: 308ms
memory: 31356kb
input:
200000 10000 1605 2691 1387 5825 1374 7459 99 7402 682 9720 2139 5337 421 2668 2184 7076 1430 5701 714 5962 1852 3779 489 3860 736 4750 555 3957 352 8089 252 3328 1490 3672 1103 4839 797 5574 1846 4484 2196 5876 752 2649 159 2742 558 4796 1089 5192 429 9435 1007 4938 1787 7780 1731 8192 1655 5266 83...
output:
199962 199997 200045 200070 200123 200139 200180 200255 200285 200356 200394 200431 200500 200529 200563 200603 200646 200671 200726 200786 200798 200836 200870 200907 200996 201028 201058 201125 201148 201219 201266 201313 201363 201406 201444 201511 201542 201598 201605 201670 201704 201766 201789...
result:
ok single line: '199962 199997 200045 200070 20...50 200018 200016 199998 199987 '