QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#747564#5035. foo~mygr0 27ms308820kbC++142.9kb2024-11-14 17:32:162024-11-14 17:32:16

Judging History

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

  • [2024-11-14 17:32:16]
  • 评测
  • 测评结果:0
  • 用时:27ms
  • 内存:308820kb
  • [2024-11-14 17:32:16]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define db double
#define fi first
#define se second
using namespace std;
const int Max=6e5+5,Mod=998244353,inf=0x7fffffff,KMax=32;
namespace mygr{
	ll qpow(ll a,ll b){
		ll ans=1;
		while(b)
		{	if(b&1)
			ans=(ans*a)%Mod;
			a=(a*a)%Mod;b>>=1;
		}return ans;}
	ll read()
	{
		char c=getchar();
		ll w=1,a=0;
		while(!isdigit(c)){
			if(c=='-')w=-1;
			c=getchar();}
		while(isdigit(c)){
			a=a*10+c-'0';
			c=getchar();}
		return a*w;
	}
	struct graph{
		struct edge{
			int to,next;
		}p[Max*2];
		int head[Max],last[Max],idx=0;
		void add(int u,int v)
		{
			if(!head[u])
				head[u]=++idx;
			else
				p[last[u]].next=++idx;
			last[u]=idx;
			p[idx].to=v;
		}
	};
	struct vector2{
		db x,y;
		vector2()
		{x=y=0;}
		vector2(db xx,db yy)
		{x=xx;y=yy;}
		friend vector2 operator + (vector2 A,vector2 B)
		{return vector2(A.x+B.x,A.y+B.y);}
		friend vector2 operator - (vector2 A,vector2 B)
		{return vector2(A.x-B.x,A.y-B.y);}
		friend db operator * (vector2 A,vector2 B)
		{return A.x*B.y-A.y*B.x;}
		friend db dot(vector2 A,vector2 B)
		{return A.x*B.x+A.y*B.y;}
	};
}
using namespace mygr;
int n,K;
struct sol{
	struct Stack{
		int s[Max],head,p[Max][KMax],x[Max][KMax],p2[Max][KMax],ms[KMax];
		bool (*cmp)(int A,int B);
		void insert(int num,int nf[])
		{
			int Mx[KMax],Mx2[KMax];
			for(int i=0;i<=K;i++)
			{
				Mx2[i]=Mx[i]=nf[i]+1;
			}
				
			while(head and (*cmp)(s[head],num))
			{
				for(int i=0;i<=K;i++)
				{
					Mx[i]=max(Mx[i],x[head][i]+1);
					Mx2[i]=max(Mx2[i],p2[head][i]+1);
				}
				head--;
			}
			head++;
			s[head]=num;
			for(int i=0;i<=K;i++)
			{
				p[head][i]=max(p[head-1][i]+1,Mx[i]);
				p2[head][i]=Mx2[i];
				ms[i]=max(ms[i],p2[head][i]);
				x[head][i]=Mx[i]-1;
			}
		}
	}s;
	void clear()
	{
		s.head=0;
		memset(s.ms,0,sizeof(s.ms));
		memset(s.p,0,sizeof(s.p));
		memset(s.p2,0,sizeof(s.p2));
		memset(s.x,0,sizeof(s.x));
		memset(s.s,0,sizeof(s.s));
	}
}S1;
int f[Max][KMax];
bool cmp1(int A,int B)
{
	return A<B;
}
bool cmp2(int A,int B)
{
	return A>B;
}
int solve(int a[])
{
	memset(f,0,sizeof(f));
	for(int i=0;i<=K;i++)
		S1.s.ms[i]=S1.s.p[0][i]=-inf;
	for(int i=1;i<=K;i++)
		f[0][i]=-inf;
	for(int i=1;i<=n;i++)
	{
		S1.s.insert(a[i],f[i-1]);
		for(int j=1;j<=K;j++)
			f[i][j]=max(S1.s.p[S1.s.head][j-1],S1.s.ms[j-1]);
		f[i][0]=-inf;
	}
	if(K==0)
		return max(S1.s.ms[0],S1.s.p[S1.s.head][0]);
	return f[n][K];
}
int a[Max*2];
signed main()
{
	S1.s.cmp=cmp1;
	scanf("%d%d",&n,&K);
	int pos=-1;
	for(int i=1;i<=n;i++)
	{
		a[i]=read();
		if(a[i]==n)pos=i;
	}
	for(int i=1;i<pos;i++)
		swap(a[i],a[n+i]);
	for(int i=1;i<=n;i++)
		swap(a[i],a[i+pos-1]);
	int ans=solve(a);
	S1.clear();
	
	reverse(a+2,a+1+n);
	ans=max(ans,solve(a));
	printf("%d",ans);
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 10
Accepted
time: 7ms
memory: 306396kb

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: 24ms
memory: 307296kb

input:

13 6
13 9 3 4 12 6 5 1 8 10 11 7 2

output:

13

result:

ok "13"

Test #3:

score: 10
Accepted
time: 19ms
memory: 306992kb

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:

16

result:

ok "16"

Test #4:

score: 10
Accepted
time: 16ms
memory: 306736kb

input:

25 9
1 11 10 23 9 24 7 8 19 3 5 21 18 12 15 16 17 13 2 20 14 22 4 6 25

output:

23

result:

ok "23"

Test #5:

score: 10
Accepted
time: 12ms
memory: 307416kb

input:

13 2
1 4 2 3 5 6 7 8 9 10 12 11 13

output:

12

result:

ok "12"

Test #6:

score: 10
Accepted
time: 23ms
memory: 307272kb

input:

17 5
4 2 3 6 5 1 7 8 13 16 11 12 9 14 15 10 17

output:

15

result:

ok "15"

Test #7:

score: 10
Accepted
time: 16ms
memory: 306380kb

input:

8 2
1 2 5 6 3 4 7 8

output:

8

result:

ok "8"

Test #8:

score: 10
Accepted
time: 8ms
memory: 306832kb

input:

11 5
3 11 2 10 6 5 1 4 8 7 9

output:

11

result:

ok "11"

Test #9:

score: 10
Accepted
time: 15ms
memory: 307432kb

input:

10 1
5 3 4 1 10 8 9 6 7 2

output:

6

result:

ok "6"

Test #10:

score: 10
Accepted
time: 12ms
memory: 307580kb

input:

16 2
15 12 14 9 11 13 1 3 10 8 5 2 16 4 6 7

output:

9

result:

ok "9"

Test #11:

score: 10
Accepted
time: 15ms
memory: 307204kb

input:

6 3
4 1 5 6 2 3

output:

6

result:

ok "6"

Test #12:

score: 10
Accepted
time: 11ms
memory: 307524kb

input:

1 1
1

output:

1

result:

ok "1"

Test #13:

score: 10
Accepted
time: 19ms
memory: 307472kb

input:

16 5
7 14 13 16 10 1 9 11 3 8 2 4 5 15 12 6

output:

14

result:

ok "14"

Test #14:

score: 10
Accepted
time: 20ms
memory: 307992kb

input:

10 3
10 1 7 2 8 6 9 5 4 3

output:

9

result:

ok "9"

Test #15:

score: 10
Accepted
time: 24ms
memory: 307996kb

input:

23 9
12 11 22 2 5 9 1 4 18 19 17 16 23 20 6 13 8 21 10 7 14 15 3

output:

23

result:

ok "23"

Test #16:

score: 10
Accepted
time: 20ms
memory: 306964kb

input:

15 4
4 3 8 13 12 1 14 9 15 10 7 11 2 6 5

output:

13

result:

ok "13"

Test #17:

score: 10
Accepted
time: 23ms
memory: 307284kb

input:

24 7
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

output:

24

result:

ok "24"

Test #18:

score: 10
Accepted
time: 20ms
memory: 307552kb

input:

4 2
1 2 3 4

output:

4

result:

ok "4"

Test #19:

score: 0
Wrong Answer
time: 27ms
memory: 306796kb

input:

18 1
1 3 5 7 9 11 13 15 17 18 16 14 12 10 8 6 4 2

output:

3

result:

wrong answer 1st words differ - expected: '10', found: '3'

Subtask #2:

score: 0
Wrong Answer

Test #21:

score: 0
Wrong Answer
time: 24ms
memory: 308820kb

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:

15

result:

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

Subtask #3:

score: 0
Wrong Answer

Test #36:

score: 0
Wrong Answer
time: 15ms
memory: 307920kb

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:

236

result:

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

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #2:

0%