QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#352012 | #5035. foo~ | ANIG | 0 | 148ms | 366328kb | C++23 | 2.1kb | 2024-03-12 19:23:17 | 2024-03-12 19:23:17 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define F(i,l,r) for(int i=(l);i<=(r);i++)
#define D(i,l,r) for(int i=(l);i>=(r);i--)
const int N=1.2e6+5,inf=1e9,M=35;
struct tr{
int fa[N];
int f(int x){
if(x==fa[x])return x;
return fa[x]=f(fa[x]);
}
void hb(int a,int b){
if(f(a)!=f(b))fa[f(b)]=f(a);
}
}t1,t2;
struct node{
int lst,nxt,laz;
}l1[N],l2[N];
int n,k,w[N],p[N],lst[N],nxt[N],res,f[M][N],f1[N],f2[N];
vector<int>st,g1[N],g2[N];
deque<int>qs;
void del(node*q,int x){
if(q[x].laz)q[q[x].nxt].laz+=q[x].laz;
q[q[x].lst].nxt=q[x].nxt;
q[q[x].nxt].lst=q[x].lst;
}
void upt(node*q,int x,int*g){
while(q[x].lst&&g[q[x].lst]<=g[x]+q[x].laz)del(q,q[x].lst);
}
void Solve(){
F(i,1,n)g1[i].clear(),g2[i].clear();
qs.clear();
for(int i=1;i<=n;i++)qs.push_back(w[i]);
while(qs.front()!=n)qs.push_front(qs.back()),qs.pop_back();
for(int i=1;i<=n;i++)p[i]=qs[i-1],t1.fa[i]=t2.fa[i]=i;
p[0]=p[n+1]=inf;
st.clear();
st.push_back(0);
F(i,1,n){
while(p[st.back()]<p[i])st.pop_back();
lst[i]=st.back();
st.push_back(i);
}
st.clear();
st.push_back(n+1);
D(i,n,1){
while(p[st.back()]<p[i])st.pop_back();
nxt[i]=st.back();
st.push_back(i);
}
F(i,1,n)g1[lst[i]].push_back(i),g2[nxt[i]].push_back(i);
memset(f,-0x3f,sizeof(f));
f[0][0]=0;
F(t,1,k){
memset(f1,0,sizeof(f1));
memset(f2,0,sizeof(f2));
int tg=0;
F(i,1,n)l1[i]={i-1,i+1,0},l2[i]={i-1,i+1,0};
F(i,1,n){
f1[i]=f[t-1][i-1]-(i-1);
f2[i]=f[t-1][i-1]-i+1;
D(u,n,lst[i]+1)f1[u]++;
for(auto u:g2[i]){F(v,1,u)f2[v]--;}
F(u,1,i)f[t][i]=max(f[t][i],max(f1[u],f2[u]+i));
}
}
F(i,1,n)res=max(res,f[k][i]);
}
signed main(){
#ifdef zzafanti
freopen("in.txt","r",stdin);
#endif
#ifdef orz
freopen("out.txt","w",stdout);
#endif
cin>>n>>k;
F(i,1,n)cin>>w[i];
Solve();
reverse(w+1,w+n+1);
Solve();
cout<<res;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 44ms
memory: 363256kb
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:
18
result:
wrong answer 1st words differ - expected: '20', found: '18'
Subtask #2:
score: 0
Time Limit Exceeded
Test #21:
score: 0
Time Limit Exceeded
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:
result:
Subtask #3:
score: 0
Wrong Answer
Test #36:
score: 0
Wrong Answer
time: 148ms
memory: 366328kb
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:
229
result:
wrong answer 1st words differ - expected: '237', found: '229'
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Skipped
Dependency #2:
0%