QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#352019 | #5035. foo~ | ANIG | 0 | 139ms | 366804kb | C++23 | 2.3kb | 2024-03-12 19:34:07 | 2024-03-12 19:34:08 |
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,tr&t){
while(q[x].lst&&g[q[x].lst]<=g[x]+q[x].laz)t.hb(x,q[x].lst),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];
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));
F(i,1,n)t1.fa[i]=t2.fa[i]=i;
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;
upt(l1,i,f1,t1);
l1[t1.f(lst[i]+1)].laz++;
upt(l1,t1.f(lst[i]+1),f1,t1);
for(auto u:g2[i]){F(v,u+1,n)f2[v]++;tg--;}
F(u,1,i)f[t][i]=max(f[t][i],f2[u]+i+tg);
int x=l1[0].nxt;
f[t][i]=max(f[t][i],f1[x]+l1[x].laz);
}
}
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: 40ms
memory: 366804kb
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:
19
result:
wrong answer 1st words differ - expected: '20', found: '19'
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: 139ms
memory: 366684kb
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:
226
result:
wrong answer 1st words differ - expected: '237', found: '226'
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Skipped
Dependency #2:
0%