QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#740476#5035. foo~jinqihao20230 18ms20696kbC++141.5kb2024-11-13 10:04:472024-11-13 10:04:47

Judging History

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

  • [2024-11-13 10:04:47]
  • 评测
  • 测评结果:0
  • 用时:18ms
  • 内存:20696kb
  • [2024-11-13 10:04:47]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=6e5+5,inf=1e9;
int n,k,a[N],ans,f[N],g[N],b[N];
struct dsu
{
	int prt[N],fv[N],add,maxn,lst,tot;
	int gf(int x){if(x==prt[x])return x;return prt[x]=gf(prt[x]);}
	void addsuf(int x,int v)
	{
		if(x>tot)return ;
		maxn+=v,lst+=v,x=gf(x);
		while(x>1 && fv[x]<=v)maxn-=fv[x],v-=fv[x],prt[x]=gf(x-1),x=gf(x);
		if(x>1)maxn-=v,fv[x]-=v;
	}
	void decpre(int x,int v){add-=v,addsuf(x+1,v);}
	int askmax(){return maxn+add;}
	void ins(int v)
	{
		tot++,prt[tot]=tot,fv[tot]=lst;
		addsuf(tot,v-add),lst=v-add;
	}
	void clr()
	{
		add=0,maxn=0,lst=0,tot=0;
		for(int i=1;i<=tot;i++)prt[i]=i,fv[i]=0;
	}
}t1,t2;
int st[N],top;
void solve(int *a)
{
	//for(int i=1;i<=n;i++)printf("%d ",a[i]);printf("\n");
	//for(int j=1;j<=n;j++)f[j]=-inf;
	for(int i=1;i<=k;i++)
	{
		t1.clr(),t2.clr();
		for(int j=0;j<=n;j++)g[j]=f[j],f[j]=0;
		top=0;
		for(int j=1;j<=n;j++)
		{
			t1.ins(g[j-1]),t2.ins(g[j-1]);
			t2.addsuf(1,1);
			while(top && a[st[top]]<a[j])t2.decpre(st[top],1),top--;
			t1.addsuf(st[top]+1,1);
			top++,st[top]=j,f[j]=max(t1.askmax(),t2.askmax());
		}
		f[i-1]=-inf;
	}
	for(int i=k;i<=n;i++)ans=max(ans,f[i]);
}
int main()
{
	scanf("%d %d",&n,&k);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	int pn=0;
	for(int i=1;i<=n;i++)if(a[i]==n)pn=i;
	for(int i=1;i<=n;i++)b[i]=a[(i+pn-2)%n+1];
	solve(b);
	for(int i=1;i<=n;i++)b[i]=a[(i-(n-pn)+n*2-1)%n+1];
	reverse(b+1,b+n+1);
	solve(b);
	printf("%d\n",ans);
	return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

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:

23

result:

wrong answer 1st words differ - expected: '20', found: '23'

Subtask #2:

score: 0
Wrong Answer

Test #21:

score: 0
Wrong Answer
time: 18ms
memory: 20696kb

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:

47

result:

wrong answer 1st words differ - expected: '25', found: '47'

Subtask #3:

score: 0
Wrong Answer

Test #36:

score: 0
Wrong Answer
time: 2ms
memory: 18204kb

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:

395

result:

wrong answer 1st words differ - expected: '237', found: '395'

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #2:

0%