QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#743950 | #5035. foo~ | tuxuanming2024 | 0 | 51ms | 340472kb | C++20 | 1.4kb | 2024-11-13 20:24:02 | 2024-11-13 20:24:12 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=6e5+5,K=35;
int n,m,a[N],b[N],f[N][K],r[N],mx[N][K],st[N],top,pre[N][K],suf[N][K],ans;
void Max(int &x,const int &y) {x=max(x,y);}
void solve()
{
// for(int i=1;i<=n;i++) cerr<<b[i]<<" \n"[i==n];
for(int i=n;i>=1;i--)
{
r[i]=i+1;
while(r[i]<=n&&b[r[i]]<b[i]) r[i]=r[r[i]];
}
memset(f,-0x3f,sizeof(f)),memset(mx,-0x3f,sizeof(mx));
memset(pre,-0x3f,sizeof(pre)),memset(suf,-0x3f,sizeof(suf));
st[top=1]=1,f[1][1]=mx[1][1]=pre[1][1]=suf[1][1]=1;
for(int i=2;i<=n;i++)
{
while(top&&b[i]>b[st[top]]) top--;
for(int j=1;j<=m;j++)
{
Max(pre[i][j],f[i-1][j-1]+1);
Max(suf[i][j],mx[i-1][j-1]+1);
}
int l=st[top];
for(int j=1;j<=m;j++)
{
Max(pre[i][j],pre[l][j]);
Max(suf[i][j],suf[l][j]+1);
f[i][j]=max(pre[i][j],suf[i][j]);
mx[i][j]=max(mx[i-1][j],f[i][j]);
if(r[i]<=n) Max(pre[r[i]][j],pre[i][j]+1);
}
st[++top]=i;
}
for(int i=1;i<=n;i++) ans=max(ans,f[i][m]);
}
int main()
{
#ifdef LOCAL
freopen("1.in","r",stdin);
freopen("1.out","w",stdout);
freopen("1.err","w",stderr);
#endif
cin>>n>>m; int pos=0;
for(int i=1;i<=n;i++)
{
cin>>a[i];
if(a[i]==n) pos=i;
}
int cnt=0; b[++cnt]=a[pos];
for(int i=pos+1;i!=pos;i=i%n+1) b[++cnt]=a[i];
solve();
for(int i=1;i<n;i++) b[i]=b[i+1];
b[n]=n,reverse(b+1,b+1+n);
solve(),cout<<ans<<"\n";
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 10
Accepted
time: 47ms
memory: 338968kb
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: 44ms
memory: 339544kb
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: 27ms
memory: 340472kb
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:
18
result:
wrong answer 1st words differ - expected: '16', found: '18'
Subtask #2:
score: 0
Wrong Answer
Test #21:
score: 0
Wrong Answer
time: 51ms
memory: 337740kb
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:
46981
result:
wrong answer 1st words differ - expected: '25', found: '46981'
Subtask #3:
score: 0
Wrong Answer
Test #36:
score: 0
Wrong Answer
time: 32ms
memory: 338460kb
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:
1056
result:
wrong answer 1st words differ - expected: '237', found: '1056'
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Skipped
Dependency #2:
0%