QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#590828 | #9222. Price Combo | Displace_ | WA | 1398ms | 208588kb | C++14 | 3.3kb | 2024-09-26 11:52:59 | 2024-09-26 11:52:59 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dou;
typedef pair<int,int> pii;
#define fi first
#define se second
#define mapa make_pair
typedef long double ld;
typedef unsigned long long ull;
template <typename T>inline void read(T &x){
x=0;char c=getchar();bool f=0;
for(;c<'0'||c>'9';c=getchar()) f|=(c=='-');
for(;c>='0'&&c<='9';c=getchar())
x=(x<<1)+(x<<3)+(c^48);
x=(f?-x:x);
}
const int N=2e5+5;
const ll inf=1e18;
int n;
int a[N], b[N];
int rka[N], rkb[N], px[N], py[N];
inline bool cmp1(int x, int y){return a[x]<a[y];}
inline bool cmp2(int x, int y){return b[x]<b[y];}
struct mat{
ll a[4][4];
mat(){
for(int i=0; i<4; ++i) for(int j=0; j<4; ++j) a[i][j]=inf;
}
inline friend mat operator *(mat x, mat y) {
mat ret;
for(int i=0; i<4; ++i){
for(int j=0; j<4; ++j){
for(int k=0; k<4; ++k){
ret.a[i][j]=min(ret.a[i][j], x.a[i][k]+y.a[k][j]);
}
}
}
return ret;
}
inline friend mat operator +(mat x, mat y){
mat ret;
for(int i=0; i<4; ++i) for(int j=0; j<4; ++j) ret.a[i][j]=min(x.a[i][j], y.a[i][j]);
return ret;
}
inline friend bool operator !=(mat x, mat y){
for(int i=0; i<4; ++i) for(int j=0; j<4; ++j) if(x.a[i][j]!=y.a[i][j]) return true;
return false;
}
}tr[N<<2], tag[N<<2], I, tem, bs;
int idx;
inline void build(int p, int l, int r){
tag[p]=I;
if(l==r){
if(l==n+1){
tr[p].a[0][0]=0;
}
return ;
}
int mid=(l+r)>>1;
build(p<<1, l, mid); build(p<<1|1, mid+1, r);
tr[p]=tr[p<<1]+tr[p<<1|1];
}
inline void push_down(int p){
if(tag[p]!=I){
tr[p<<1]=tr[p<<1]*tag[p]; tag[p<<1]=tag[p<<1]*tag[p];
tr[p<<1|1]=tr[p<<1|1]*tag[p]; tag[p<<1|1]=tag[p<<1|1]*tag[p];
tag[p]=I;
}
}
inline void qry(int p, int l, int r, int L, int R){
if(L<=l&&r<=R) {
tem=tem+tr[p];
return ;
}
int mid=(l+r)>>1;
push_down(p);
if(L<=mid) qry(p<<1, l, mid, L, R);
if(R>mid) qry(p<<1|1, mid+1, r, L, R);
}
inline void mdf(int p, int l, int r, int L, int R){
if(L>R) return ;
if(L<=l&&r<=R){
tr[p]=tr[p]*tem; tag[p]=tag[p]*tem;
return ;
}
int mid=(l+r)>>1;
push_down(p);
if(L<=mid) mdf(p<<1, l, mid, L, R);
if(R>mid) mdf(p<<1|1, mid+1, r, L, R);
tr[p]=tr[p<<1]+tr[p<<1|1];
}
inline void st(int p, int l, int r, int x){
if(l==r){
tr[p]=tem;
return ;
}
int mid=(l+r)>>1;
push_down(p);
if(x<=mid) st(p<<1, l, mid, x);
else st(p<<1|1, mid+1, r, x);
tr[p]=tr[p<<1]+tr[p<<1|1];
}
int main(){
// freopen("D:\\nya\\acm\\C\\test.in","r",stdin);
// freopen("D:\\nya\\acm\\C\\test.out","w",stdout);
for(int i=0; i<4; ++i) I.a[i][i]=0;
read(n);
for(int i=1; i<=n; ++i) read(a[i]);
for(int i=1; i<=n; ++i) read(b[i]);
for(int i=1; i<=n; ++i) rka[i]=rkb[i]=i;
sort(rka+1, rka+n+1, cmp1);
sort(rkb+1, rkb+n+1, cmp2);
for(int i=1; i<=n; ++i) px[rka[i]]=i, py[rkb[i]]=i;
build(1, 1, n+1);
for(int _=n; _>=0; --_){
int i=rka[_];
tem=bs;
qry(1, 1, n+1, py[i], n+1);
st(1, 1, n+1, py[i]);
mat v1=bs;
v1.a[1][0]=v1.a[3][2]=0;
v1.a[0][1]=v1.a[2][3]=b[rkb[py[i]]];
tem=v1;
mdf(1, 1, n+1, py[i]+1, n+1);
mat v2=bs;
v2.a[2][0]=v2.a[3][1]=0;
v2.a[0][2]=v2.a[1][3]=a[i];
tem=v2;
mdf(1, 1, n+1, 1, py[i]);
}
ll ans=inf;
for(int i=0; i<4; ++i) ans=min(ans, tr[1].a[0][i]);
printf("%lld\n", ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 208524kb
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: 7ms
memory: 205424kb
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: 1398ms
memory: 208588kb
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:
154816477588
result:
wrong answer 1st lines differ - expected: '154816494865', found: '154816477588'