QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#409365 | #6627. Line Town | Dinal | 0 | 0ms | 20092kb | C++14 | 1.7kb | 2024-05-11 22:57:52 | 2024-05-11 22:57:53 |
Judging History
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=1061109567;
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==1061109567?-1:ans);
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 3
Accepted
time: 0ms
memory: 18244kb
input:
10 1 1 1 1 1 -1 -1 -1 1 -1
output:
-1
result:
ok 1 number(s): "-1"
Test #2:
score: 0
Wrong Answer
time: 0ms
memory: 20092kb
input:
10 1 1 1 1 1 1 -1 1 1 -1
output:
-1
result:
wrong answer 1st numbers differ - expected: '3', found: '-1'
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: 4
Accepted
time: 0ms
memory: 18176kb
input:
10 3 10 5 -9 7 2 -6 1 8 0
output:
-1
result:
ok 1 number(s): "-1"
Test #61:
score: 0
Wrong Answer
time: 0ms
memory: 16008kb
input:
10 -9 0 -1 7 5 10 6 3 2 -8
output:
-1
result:
wrong answer 1st numbers differ - expected: '13', found: '-1'
Subtask #6:
score: 0
Skipped
Dependency #5:
0%
Subtask #7:
score: 0
Skipped
Dependency #3:
0%
Subtask #8:
score: 0
Skipped
Dependency #1:
0%