QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#811182#9865. Dollskkkgjyismine4WA 3ms10020kbC++201.4kb2024-12-12 16:14:292024-12-12 16:14:30

Judging History

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

  • [2025-01-08 13:49:40]
  • hack成功,自动添加数据
  • (/hack/1434)
  • [2024-12-12 16:14:30]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:10020kb
  • [2024-12-12 16:14:29]
  • 提交

answer

#include<bits/stdc++.h>
#define N 100005
using namespace std;
int ct[N],tr[N],n,a[N],tr1[N],tr2[N],f[N][20],g[N][20],dp[N];
int qry(int x,int v){
	for(int i=19;i>=0;--i)
		if(x+(1<<i)-1<=n&&g[x][i]>v)x+=(1<<i);
	return x;
}
int qry1(int x,int v){
	for(int i=19;i>=0;--i)
		if(x+(1<<i)-1<=n&&f[x][i]<v)x+=(1<<i);
	return x;
}
int st[N],tl,st1[N],tl1;
void solve(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d",&a[i]),tr1[i]=tr2[i]=0,f[i][0]=g[i][0]=a[i];
	for(int j=1;(1<<j)<=n;++j)
		for(int i=1;i+(1<<j)-1<=n;++i)
			f[i][j]=max(f[i][j-1],f[i+(1<<j-1)][j-1]),
			g[i][j]=min(g[i][j-1],g[i+(1<<j-1)][j-1]);
	tl=tl1=0;
	for(int i=n;i;--i){
		while(tl&&a[st[tl]]<a[i])tr1[st[tl--]]=0;
		if(tl)tr1[st[tl]]=min(tr[st[tl]],qry(st[tl],a[i])-1);st[++tl]=i;
		while(tl1&&a[st1[tl1]]>a[i])tr2[st1[tl1--]]=0;
		if(tl1)tr2[st1[tl1]]=min(tr[st1[tl1]],qry1(st1[tl1],a[i])-1);st1[++tl1]=i;
		for(int j=i;j<=n;++j)ct[j]=0;
		for(int j=i;j<=n;++j){
			if(tr1[j])++ct[j-1],--ct[tr1[j]+1];
			if(tr2[j])++ct[j-1],--ct[tr2[j]+1];
		}tr[i]=dp[i]=0;
		for(int j=i+1;j<=n;++j){
			ct[j]+=ct[j-1];
			if(!ct[j]){tr[i]=j-1;break;}
		}if(!tr[i])tr[i]=n;
//		cout<<i<<" "<<tr[i]<<endl;
	}
	dp[0]=0;int ans=0;
	for(int i=1;i<=n;++i){
		for(int j=1;j<i;++j)if(tr[j]>=i)dp[i]=max(dp[i],dp[j-1]+i-j);
		ans=max(ans,dp[i]);
	}printf("%d\n",ans);
}
int main(){
	int T;cin>>T;
	while(T--)solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 10020kb

input:

8
4
2 1 4 3
4
1 4 2 3
4
3 1 4 2
5
1 3 5 2 4
5
1 4 2 5 3
5
2 5 3 1 4
6
1 3 6 5 2 4
6
2 5 1 3 6 4

output:

3
3
2
3
3
3
4
4

result:

ok 8 numbers

Test #2:

score: -100
Wrong Answer
time: 3ms
memory: 7880kb

input:

5913
1
1
2
1 2
2
2 1
3
1 2 3
3
1 3 2
3
2 1 3
3
2 3 1
3
3 1 2
3
3 2 1
4
1 2 3 4
4
1 2 4 3
4
1 3 2 4
4
1 3 4 2
4
1 4 2 3
4
1 4 3 2
4
2 1 3 4
4
2 1 4 3
4
2 3 1 4
4
2 3 4 1
4
2 4 1 3
4
2 4 3 1
4
3 1 2 4
4
3 1 4 2
4
3 2 1 4
4
3 2 4 1
4
3 4 1 2
4
3 4 2 1
4
4 1 2 3
4
4 1 3 2
4
4 2 1 3
4
4 2 3 1
4
4 3 1 2
4...

output:

0
1
1
2
2
2
2
2
2
3
3
3
3
3
3
3
3
3
3
2
3
3
2
3
3
3
3
3
3
3
3
3
3
4
4
4
4
4
4
4
4
4
4
3
4
4
3
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
3
4
4
3
4
4
3
4
3
3
3
4
3
4
4
4
4
3
3
3
4
4
4
4
3
4
4
3
4
4
4
4
3
3
3
4
4
4
4
3
4
3
3
3
4
3
4
4
3
4
4
3
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
3
4
4
3
4
4
4
4
4
4
4
...

result:

wrong answer 70th numbers differ - expected: '3', found: '4'