QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#409364#6627. Line TownDinal0 0ms19548kbC++141.7kb2024-05-11 22:56:412024-05-11 22:56:42

Judging History

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

  • [2024-05-11 22:56:42]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:19548kb
  • [2024-05-11 22:56:41]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

int n,m;

const int N=500010;
int a[N],b[N];
int f[N][2][2];
struct BIT{
	int a[N];
	int lowbit(int x){return x&-x;}
	void clear(){for(int i=1;i<=m;++i)a[i]=0;}
	void add(int x,int v){for(;x<=m;x+=lowbit(x))a[x]+=v;}
	int ask(int x){int res=0;for(;x;x-=lowbit(x))res+=a[x];return res;}
}fwk;
int pr[N],sf[N];
int main(){
	cin>>n;
	for(int i=1;i<=n;++i)cin>>a[i],b[i]=abs(a[i]);
	sort(b+1,b+n+1);
	m=unique(b+1,b+n+1)-b-1;
	for(int i=1;i<=n;++i){
		if(a[i]>=0)a[i]=lower_bound(b+1,b+m+1,a[i])-b;
		else a[i]=-(lower_bound(b+1,b+m+1,-a[i])-b);
		// printf("%d ",a[i]);
	}
	// puts("");
	for(int i=1;i<=n;++i){
		pr[i]=fwk.ask(abs(a[i])-1);
		fwk.add(abs(a[i]),1);
	}
	fwk.clear();
	for(int i=n;i>=1;--i){
		sf[i]=fwk.ask(abs(a[i])-1);
		fwk.add(abs(a[i]),1);
		// swap(sf[i],pr[i]);
	}
	// for(int i=1;i<=n;++i)printf("%d ",sf[i]);puts("");
	// for(int i=1;i<=n;++i)printf("%d ",pr[i]);puts("");
	memset(f,0x3f,sizeof f);
	f[0][1][1]=f[0][0][0]=0;
	for(int i=0;i<=n;++i){
		if(i==0){
			
		// printf("%d:%d %d %d %d\n",i,f[i][0][0],f[i][0][1],
			// f[i][1][0],f[i][1][1]);
			continue;
		}
		if(a[i]>=0){
			f[i][1][1]=min(f[i-1][1][0]+sf[i],f[i-1][0][1]+pr[i]);
			f[i][0][1]=f[i-1][0][0]+sf[i];
			f[i][1][0]=f[i-1][0][0]+pr[i];
			// f[i][0][0]
		}else{
			f[i][0][0]=min(f[i-1][0][1]+sf[i],f[i-1][1][0]+pr[i]);
			f[i][1][0]=f[i-1][1][1]+sf[i];
			f[i][0][1]=f[i-1][1][1]+pr[i];
		}
		// printf("%d:%d %d %d %d\n",i,f[i][0][0],f[i][0][1],
			// f[i][1][0],f[i][1][1]);
	}
	int ans=2e9;
	for(int i=0;i<2;++i)
		for(int j=0;j<2;++j)	
		ans=min(ans,f[n][i][j]);
	printf("%d\n",ans);
	return 0;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

input:

10
1 1 1 1 1 -1 -1 -1 1 -1

output:

1061109567

result:

wrong answer 1st numbers differ - expected: '-1', found: '1061109567'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Wrong Answer

Test #60:

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

input:

10
3 10 5 -9 7 2 -6 1 8 0

output:

1061109567

result:

wrong answer 1st numbers differ - expected: '-1', found: '1061109567'

Subtask #6:

score: 0
Skipped

Dependency #5:

0%

Subtask #7:

score: 0
Skipped

Dependency #3:

0%

Subtask #8:

score: 0
Skipped

Dependency #1:

0%