QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#740307#5035. foo~leihonglongyin0 54ms71856kbC++201.3kb2024-11-13 08:45:542024-11-13 08:45:55

Judging History

你现在查看的是最新测评结果

  • [2024-11-13 08:45:55]
  • 评测
  • 测评结果:0
  • 用时:54ms
  • 内存:71856kb
  • [2024-11-13 08:45:54]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;const int N=6e5+5;
int n,m,w,p[N],P[N],tot,st[N],id[N],s[N],ls[N],rs[N],f[N],g[N],mx[21][N],v[N],ans;
int ask(int l,int r){int len=__lg(r-l+1);return max(mx[len][l],mx[len][r-(1<<len)+1]);}
void sol(){memset(f,-0x3f,sizeof(f)),f[0]=tot=0;
	for(int i=w;i<=n;i++)p[i-w+1]=P[i];for(int i=1;i<w;i++)p[n-w+1+i]=P[i];
	for(int i=1;i<=n;i++){int lst=0;while(tot&&st[tot]<p[i])rs[id[tot]]=lst,lst=id[tot--];
		ls[i]=lst,st[++tot]=p[i],id[tot]=i;
	}
	for(int k=1;k<=m;k++){memset(g,-0x3f,sizeof(g)),tot=0;for(int i=1;i<=n;i++)mx[0][i]=f[i];
		for(int j=1;j<=20;j++)for(int i=1;i<=n-(1<<j)+1;i++)mx[j][i]=max(mx[j-1][i],mx[j-1][i+(1<<j-1)]);
		for(int res=-1e9,i=1;i<=n;i++){while(tot&&st[tot]<p[i])tot--;
			if(tot)s[tot]=max(ask(id[tot-1],id[tot]-1),s[tot-1])+1;
			v[i]=f[i-1];int u=ls[i];while(u)v[i]=max(v[i],v[u]),u=rs[u];res=max(res,++v[i]);
			g[i]=max(res,max(s[tot],ask(id[tot],i-1))+1),st[++tot]=p[i],id[tot]=i;
		}memcpy(f,g,sizeof(f));
	}for(int i=1;i<=n;i++)ans=max(ans,f[i]);
}
int main(){//freopen("seq.in","r",stdin),freopen("seq.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n>>m,s[0]=-1e9;for(int i=1;i<=n;i++)cin>>P[i],P[i]==n&&(w=i);
	sol(),reverse(P+1,P+1+n),sol(),cout<<ans;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 10
Accepted
time: 3ms
memory: 34272kb

input:

23 6
16 20 22 4 21 10 3 7 5 8 15 12 9 1 6 17 23 13 11 19 18 14 2

output:

20

result:

ok "20"

Test #2:

score: 10
Accepted
time: 4ms
memory: 30176kb

input:

13 6
13 9 3 4 12 6 5 1 8 10 11 7 2

output:

13

result:

ok "13"

Test #3:

score: 0
Wrong Answer
time: 0ms
memory: 32296kb

input:

25 3
25 2 3 19 5 6 7 11 8 10 9 20 4 14 21 1 17 12 13 18 15 22 23 16 24

output:

15

result:

wrong answer 1st words differ - expected: '16', found: '15'

Subtask #2:

score: 0
Wrong Answer

Test #21:

score: 10
Accepted
time: 11ms
memory: 63168kb

input:

93943 1
87243 48984 50611 19218 77699 25025 85769 28141 13380 34875 42459 66419 53472 4367 48292 16894 92171 87263 42527 67085 30687 29235 27515 81053 31421 34864 83591 70491 75344 7026 50250 63402 26773 5330 36308 76399 80032 15501 16205 71750 73964 67876 68901 70548 2043 79979 89479 19784 38838 44...

output:

25

result:

ok "25"

Test #22:

score: 10
Accepted
time: 12ms
memory: 65604kb

input:

112118 1
24338 1586 3 108269 5 53472 80391 70331 9 15335 62487 28331 13 14 16564 94323 36681 108815 32632 44382 21 22 23 24 11758 40070 21518 51991 109983 30 45524 59784 33 2068 62111 36 37 38 39 89031 30508 42 43 16414 110006 34303 47 10331 44651 50 93957 95407 22019 88681 56605 12426 28498 58 59 8...

output:

281

result:

ok "281"

Test #23:

score: 10
Accepted
time: 50ms
memory: 71292kb

input:

391400 1
158965 280194 3 4 5 369036 92293 245923 57403 10 6887 280754 277300 110148 314164 135940 17 46573 126951 111447 301107 22 23 24 25 26 247952 28 342994 339309 23647 350245 33 299608 35 36 37 263236 232063 40 41 42 43 44 39280 46 299122 11961 380375 384513 51 318009 162567 54 55 56 27356 58 6...

output:

693

result:

ok "693"

Test #24:

score: 0
Wrong Answer
time: 54ms
memory: 71856kb

input:

440571 1
243784 2 3 130039 61385 6 7 8 244611 260729 29014 12 326371 416098 15 293728 182717 66822 387603 156910 225815 413135 171756 315815 26444 302419 384825 37746 17634 391896 354575 426625 290920 34 49456 36 161212 212843 39 40 41 436888 43 102088 405279 46 47 77451 49 50 368530 52402 34143 54 ...

output:

663

result:

wrong answer 1st words differ - expected: '665', found: '663'

Subtask #3:

score: 0
Wrong Answer

Test #36:

score: 20
Accepted
time: 13ms
memory: 44552kb

input:

1992 25
144 612 1315 1966 1779 1773 1529 625 36 1849 1783 1441 1388 1558 1258 724 137 397 542 353 1162 1213 406 792 1317 882 994 298 1864 1969 103 449 508 1501 89 1721 195 778 657 222 1152 1780 613 743 1206 694 829 142 69 1973 1465 1343 655 1540 155 146 350 491 759 1695 1082 1357 1329 1745 232 1850 ...

output:

237

result:

ok "237"

Test #37:

score: 20
Accepted
time: 14ms
memory: 46628kb

input:

1992 17
785 891 1027 155 773 587 1829 255 1239 1893 1854 158 349 370 1134 1739 1186 11 1099 1149 481 361 1101 1359 1773 1568 157 1011 79 555 254 285 1260 1722 1684 577 1054 1932 590 1804 414 1415 376 1699 26 971 1554 1504 1987 1327 1184 610 652 1432 206 129 315 1390 1946 64 910 962 1189 326 497 1580...

output:

172

result:

ok "172"

Test #38:

score: 20
Accepted
time: 8ms
memory: 34348kb

input:

46 11
41 44 2 9 30 46 28 14 12 20 38 37 19 6 13 7 26 4 34 15 32 5 35 1 25 8 29 45 31 22 18 24 33 42 21 17 39 10 43 11 23 27 36 3 40 16

output:

38

result:

ok "38"

Test #39:

score: 20
Accepted
time: 11ms
memory: 34264kb

input:

53 18
29 23 32 11 24 27 28 16 6 9 3 20 8 38 43 49 18 26 41 53 31 19 48 34 44 52 45 5 30 17 2 13 15 40 1 50 21 14 4 22 51 35 39 7 47 25 10 12 33 42 36 46 37

output:

49

result:

ok "49"

Test #40:

score: 20
Accepted
time: 15ms
memory: 34268kb

input:

55 25
42 41 51 1 6 49 28 12 33 23 31 47 19 24 48 21 54 16 14 3 26 43 18 5 45 29 50 15 44 35 7 40 9 53 10 32 17 36 4 34 20 38 37 8 55 2 11 39 30 22 52 27 13 46 25

output:

55

result:

ok "55"

Test #41:

score: 0
Wrong Answer
time: 7ms
memory: 36472kb

input:

78 9
44 4 68 49 20 16 67 3 70 40 25 6 46 27 65 10 77 55 12 78 2 31 22 71 74 30 41 53 34 47 32 36 57 19 18 1 26 69 11 52 72 14 8 17 56 51 42 43 62 58 35 76 66 23 54 73 63 75 39 37 28 5 9 24 21 48 64 61 29 45 38 13 59 50 15 7 33 60

output:

40

result:

wrong answer 1st words differ - expected: '42', found: '40'

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #2:

0%