QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#62432#5035. foo~AFewSuns0 14ms18316kbC++142.3kb2022-11-18 21:09:032022-11-18 21:09:32

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-18 21:09:32]
  • 评测
  • 测评结果:0
  • 用时:14ms
  • 内存:18316kb
  • [2022-11-18 21:09:03]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
namespace my_std{
	#define ll long long
	#define bl bool
	ll my_pow(ll a,ll b,ll mod){
		ll res=1;
		if(!b) return 1;
		while(b){
			if(b&1) res=(res*a)%mod;
			a=(a*a)%mod;
			b>>=1;
		}
		return res;
	}
	ll qpow(ll a,ll b){
		ll res=1;
		if(!b) return 1;
		while(b){
			if(b&1) res*=a;
			a*=a;
			b>>=1;
		}
		return res;
	}
	#define db double
	#define pf printf
	#define pc putchar
	#define fr(i,x,y) for(register ll i=(x);i<=(y);i++)
	#define pfr(i,x,y) for(register ll i=(x);i>=(y);i--)
	#define go(u) for(ll i=head[u];i;i=e[i].nxt)
	#define enter pc('\n')
	#define space pc(' ')
	#define fir first
	#define sec second
	#define MP make_pair
	#define il inline
	#define inf 1e18
	#define random(x) rand()*rand()%(x)
	#define inv(a,mod) my_pow((a),(mod-2),(mod))
	il ll read(){
		ll sum=0,f=1;
		char ch=0;
		while(!isdigit(ch)){
			if(ch=='-') f=-1;
			ch=getchar();
		}
		while(isdigit(ch)){
			sum=sum*10+(ch^48);
			ch=getchar();
		}
		return sum*f;
	}
	il void write(ll x){
		if(x<0){
			x=-x;
			pc('-');
		}
		if(x>9) write(x/10);
		pc(x%10+'0');
	}
	il void writeln(ll x){
		write(x);
		enter;
	}
	il void writesp(ll x){
		write(x);
		space;
	}
}
using namespace my_std;
ll n,k,a[600060],b[600060],st[600060],top=0,ans=0;
ll f[600060],g[600060],pre[600060],suf[600060];
int main(){
	n=read();
	k=read();
	fr(i,1,n) a[i]=read();
	ll pos=1;
	fr(i,1,n) if(a[i]==n) pos=i;
	fr(i,1,n) b[i]=a[(pos+i-2)%n+1];
	fr(i,1,n) a[i]=b[i];
	fr(i,0,n) f[i]=-inf;
	f[0]=0;
	fr(_,1,k){
		fr(i,0,n){
			g[i]=f[i];
			f[i]=-inf;
		}
		ll maxx=g[0];
		top=0;
		fr(i,1,n){
			pre[i]=suf[i]=maxx+1;
			while(top&&a[st[top]]<a[i]){
				pre[i]=max(pre[i],pre[st[top]]+1);
				top--;
			}
			if(top) suf[i]=max(suf[i],suf[st[top]]+1);
			st[++top]=i;
			f[i]=max(pre[i],suf[i]);
			maxx=max(maxx,g[i]);
		}
	}
	ans=f[n];
	reverse(a+2,a+n+1);
	fr(i,0,n) f[i]=-inf;
	f[0]=0;
	fr(_,1,k){
		fr(i,0,n){
			g[i]=f[i];
			f[i]=-inf;
		}
		ll maxx=g[0];
		top=0;
		fr(i,1,n){
			pre[i]=suf[i]=maxx+1;
			while(top&&a[st[top]]<a[i]){
				pre[i]=max(pre[i],pre[st[top]]+1);
				top--;
			}
			if(top) suf[i]=max(suf[i],suf[st[top]]+1);
			st[++top]=i;
			f[i]=max(pre[i],suf[i]);
			maxx=max(maxx,g[i]);
		}
	}
	write(max(ans,f[n]));
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 10
Accepted
time: 2ms
memory: 15588kb

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: 0
Accepted
time: 4ms
memory: 13552kb

input:

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

output:

13

result:

ok "13"

Test #3:

score: 0
Accepted
time: 2ms
memory: 15660kb

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: 0
Accepted
time: 4ms
memory: 15768kb

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: 0
Accepted
time: 4ms
memory: 15776kb

input:

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

output:

12

result:

ok "12"

Test #6:

score: 0
Accepted
time: 1ms
memory: 15580kb

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: 0
Accepted
time: 2ms
memory: 15644kb

input:

8 2
1 2 5 6 3 4 7 8

output:

8

result:

ok "8"

Test #8:

score: 0
Accepted
time: 4ms
memory: 15540kb

input:

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

output:

11

result:

ok "11"

Test #9:

score: 0
Accepted
time: 4ms
memory: 15688kb

input:

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

output:

6

result:

ok "6"

Test #10:

score: -10
Wrong Answer
time: 2ms
memory: 15600kb

input:

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

output:

10

result:

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

Subtask #2:

score: 0
Wrong Answer

Test #21:

score: 0
Wrong Answer
time: 14ms
memory: 18316kb

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: 2ms
memory: 15608kb

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:

243

result:

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

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #2:

0%