QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#201956#5150. Alternating AlgorithmPlentyOfPenalty#WA 1ms9956kbC++201.1kb2023-10-05 17:55:382023-10-05 17:55:38

Judging History

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

  • [2023-10-05 17:55:38]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:9956kb
  • [2023-10-05 17:55:38]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=4e5+9;
int n,a[N],f[N],g[N];
char op[N];
pair<int,int> t[N];
int main(){
#ifdef memset0
	freopen("A.in","r",stdin);
#endif
	ios::sync_with_stdio(0),cin.tie(0);
	cin>>n,++n;
	for(int i=1;i<=n;i++){
		cin>>t[i].first;
		t[i].second=i;
	}
	vector<pair<int,int>> tmp(t+1,t+n+1);
	sort(tmp.begin(),tmp.end());
	for(int i=1;i<=n;i++){
		a[i]=lower_bound(tmp.begin(),tmp.end(),t[i])-tmp.begin()+1;
	}
	// for(int i=1;i<=n;i++)cerr<<a[i]<<" \n"[i==n];
	int ans=0;
	for(int i=1;i<=n;i++){
		if(a[i]<i){
			op[i]='L';
		}else if(a[i]>i){
			op[i]='R';
		}
	}
	for(int i=1;i<=n;i++)
		if(op[i]=='L'){
			if(i%2==1)f[i]=1;
			if(op[i-1]=='L'&&a[i-1]<a[i]){
				while(f[i]<=f[i-1])f[i]+=2;
			}
			// cerr<<"L "<<i<<" "<<a[i]<<" :: "<<f[i]<<" "<<(i-a[i])<<endl;
			ans=max(ans,f[i]+i-a[i]);
		}
	for(int i=n;i>=1;i--)
		if(op[i]=='R'){
			if(i%2==0)g[i]=1;
			if(op[i+1]=='R'&&a[i+1]>a[i]){
				while(g[i]<=g[i+1])g[i]+=2;
			}
			// cerr<<"R "<<i<<" "<<a[i]<<" :: "<<g[i]<<" "<<(a[i]-i)<<endl;
			ans=max(ans,g[i]+a[i]-i);
		}
	cout<<ans<<endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 9628kb

input:

3
8 13 4 10

output:

3

result:

ok single line: '3'

Test #2:

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

input:

5
13 12 14 10 14 12

output:

3

result:

ok single line: '3'

Test #3:

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

input:

2
2 2 1

output:

3

result:

ok single line: '3'

Test #4:

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

input:

1
300172042 474444146

output:

0

result:

ok single line: '0'

Test #5:

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

input:

1
636357447 557539481

output:

1

result:

ok single line: '1'

Test #6:

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

input:

2
139715426 368724097 417561009

output:

0

result:

ok single line: '0'

Test #7:

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

input:

2
77784868 542697475 509604021

output:

2

result:

ok single line: '2'

Test #8:

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

input:

2
698395658 71848686 699775597

output:

1

result:

ok single line: '1'

Test #9:

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

input:

2
487635147 571273621 442673389

output:

3

result:

ok single line: '3'

Test #10:

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

input:

2
502022170 254766224 258867503

output:

2

result:

ok single line: '2'

Test #11:

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

input:

2
783651505 271735448 154090385

output:

3

result:

ok single line: '3'

Test #12:

score: 0
Accepted
time: 0ms
memory: 3532kb

input:

3
423187900 701340783 708457090 788989478

output:

0

result:

ok single line: '0'

Test #13:

score: 0
Accepted
time: 0ms
memory: 9740kb

input:

3
172068101 507957913 237246316 805323765

output:

2

result:

ok single line: '2'

Test #14:

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

input:

3
309846480 218704879 536482379 754210806

output:

1

result:

ok single line: '1'

Test #15:

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

input:

3
150235215 485036833 52089968 645641645

output:

3

result:

ok single line: '3'

Test #16:

score: 0
Accepted
time: 0ms
memory: 5540kb

input:

3
735389981 669677621 733676260 858050940

output:

2

result:

ok single line: '2'

Test #17:

score: 0
Accepted
time: 0ms
memory: 7888kb

input:

3
635103474 551413670 85269704 730878535

output:

3

result:

ok single line: '3'

Test #18:

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

input:

3
287528440 314452762 846234936 452787633

output:

1

result:

ok single line: '1'

Test #19:

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

input:

3
276069955 969481471 992185356 536479156

output:

2

result:

ok single line: '2'

Test #20:

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

input:

3
225096493 88165689 415816372 360778803

output:

1

result:

ok single line: '1'

Test #21:

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

input:

3
651934487 760368054 975264908 206290402

output:

3

result:

ok single line: '3'

Test #22:

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

input:

3
668819975 16012633 798541220 258404088

output:

2

result:

ok single line: '2'

Test #23:

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

input:

3
303955151 276719749 324951113 63908344

output:

3

result:

ok single line: '3'

Test #24:

score: 0
Accepted
time: 0ms
memory: 7848kb

input:

3
419862649 709195111 424612582 548104611

output:

3

result:

ok single line: '3'

Test #25:

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

input:

3
46436854 762650424 543885894 63420906

output:

3

result:

ok single line: '3'

Test #26:

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

input:

3
663885616 817966829 428282021 750799481

output:

3

result:

ok single line: '3'

Test #27:

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

input:

3
453815838 784866392 626401113 33629018

output:

3

result:

ok single line: '3'

Test #28:

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

input:

3
612031283 905623341 296446821 317142883

output:

4

result:

ok single line: '4'

Test #29:

score: 0
Accepted
time: 0ms
memory: 9736kb

input:

3
690093550 720639503 493410469 329723725

output:

4

result:

ok single line: '4'

Test #30:

score: 0
Accepted
time: 0ms
memory: 7924kb

input:

3
640270086 11003869 302770972 380428351

output:

3

result:

ok single line: '3'

Test #31:

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

input:

3
813904638 53916473 202342438 178710524

output:

3

result:

ok single line: '3'

Test #32:

score: 0
Accepted
time: 0ms
memory: 7920kb

input:

3
858480562 107901831 70069694 624943715

output:

3

result:

ok single line: '3'

Test #33:

score: 0
Accepted
time: 0ms
memory: 7708kb

input:

3
972814426 208602080 487914166 199127689

output:

3

result:

ok single line: '3'

Test #34:

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

input:

3
527326624 369552716 30514207 190802344

output:

4

result:

ok single line: '4'

Test #35:

score: -100
Wrong Answer
time: 1ms
memory: 7584kb

input:

3
885560774 510753464 330831417 122397162

output:

3

result:

wrong answer 1st lines differ - expected: '4', found: '3'