QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#865915 | #9222. Price Combo | shung | WA | 125ms | 47600kb | C++14 | 2.2kb | 2025-01-22 08:42:04 | 2025-01-22 08:42:10 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=800005;
const long long INF=1e18;
int n,pre[N],siz[2][N<<2],now;
struct node{
long long a[2];
int b[2];
}a[N];
inline bool cmp(node x,node y){
return x.a[0]<y.a[0];
}
long long f[N][2],tr[2][N<<2][2];
inline void pushup(int k){
for(int i=0;i<2;++i){
siz[i][k]=siz[i][k<<1]^siz[i][k<<1|1];
for(int j=0;j<2;++j)tr[i][k][j]=tr[i][k<<1|1][j]+tr[i][k<<1][j^siz[i][k<<1|1]];
}
}
inline void build(int k,int l,int r){
if(l==r){
if(a[l].b[0])tr[1][k][0]=a[l].a[0],siz[1][k]=1;
else tr[0][k][0]=a[l].a[0],siz[0][k]=1;
return;
}
int mid=(l+r)>>1;
build(k<<1,l,mid),build(k<<1|1,mid+1,r);
pushup(k);
}
inline long long query(int o,int k,int l,int r,int x,int y){
if(x>y)return 0;
if(l>=x&&r<=y){
long long ans=tr[o][k][now];
now^=siz[o][k];
return ans;
}
int mid=(l+r)>>1;
if(y<=mid)return query(o,k<<1,l,mid,x,y);
if(x>mid)return query(o,k<<1|1,mid+1,r,x,y);
long long ans=query(o,k<<1|1,mid+1,r,x,y);
ans+=query(o,k<<1,l,mid,x,y);
return ans;
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;++i)scanf("%d",&a[i].a[0]);
for(int i=1;i<=n;++i)scanf("%d",&a[i].a[1]);
for(int i=1;i<=n;++i){
if(a[i].a[0]<a[i].a[1])a[i].b[0]=1,a[i].b[1]=0;
else swap(a[i].a[0],a[i].a[1]),a[i].b[0]=0,a[i].b[1]=1;
}
sort(a+1,a+n+1,cmp);
for(int i=1;i<=n;++i)pre[i]=pre[i-1]^a[i].b[0];
a[n+1].a[0]=INF;
f[n+1][1]=INF;
build(1,1,n);
for(int i=n;i;--i){
f[i][0]=f[i][1]=INF;
for(int j=0;j<2;++j){
int k=(n-i-j)&1;
if(f[i+1][j]<INF){
if(a[i].b[0])f[i][j^1]=min(f[i][j^1],f[i+1][j]+(j?0ll:a[i].a[0]));
else f[i][j]=min(f[i][j],f[i+1][j]+(k?0ll:a[i].a[0]));
}
int l=i+1,r=n+1;
while(l<r){
int mid=(l+r)>>1;
if(a[mid].a[0]>a[i].a[1])r=mid;
else l=mid+1;
}
k=(n-l+1-j)&1;
if(f[l][j]<INF){
now=j;
long long A=query(1,1,1,n,i+1,l-1);
int aa=now;
now=k;
long long B=query(0,1,1,n,i+1,l-1);
int bb=now;
if(a[i].b[1])f[i][j^pre[l-1]^pre[i]^1]=min(f[i][j^pre[l-1]^pre[i]^1],f[l][j]+A+B+(aa?0ll:a[i].a[1]));
else f[i][j^pre[l-1]^pre[i]]=min(f[i][j^pre[l-1]^pre[i]],f[l][j]+A+B+(bb?0ll:a[i].a[1]));
}
}
}
cout<<min(f[1][0],f[1][1]);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 10068kb
input:
7 10 12 19 99 10 8 49 9 14 15 199 11 7 19
output:
131
result:
ok single line: '131'
Test #2:
score: 0
Accepted
time: 0ms
memory: 10064kb
input:
7 10 12 19 99 10 8 49 9 14 15 199 11 7 19
output:
131
result:
ok single line: '131'
Test #3:
score: -100
Wrong Answer
time: 125ms
memory: 47600kb
input:
199913 1212731 2525164 3210261 2457211 1013738 1931420 923123 867112 762069 2108660 108920 2491869 867107 387025 2278045 574027 1661570 820133 1274150 2001346 779766 3305537 3000211 2418643 2108660 2001343 1074820 2754411 826712 3117447 1661569 338161 1849064 3007920 3057426 468078 3252798 1274146 4...
output:
154816494786
result:
wrong answer 1st lines differ - expected: '154816494865', found: '154816494786'