QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#592388#9222. Price ComboDisplace_TL 1789ms327344kbC++143.8kb2024-09-26 22:13:312024-09-26 22:13:32

Judging History

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

  • [2024-09-26 22:13:32]
  • 评测
  • 测评结果:TL
  • 用时:1789ms
  • 内存:327344kb
  • [2024-09-26 22:13:31]
  • 提交

answer

#pragma GCC optimize(3)
#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];
	int n1, n2;
	mat(){
		for(int i=0; i<4; ++i) for(int j=0; j<4; ++j) a[i][j]=inf;
		n1=4; n2=4;
	}
	inline friend mat operator *(mat x, mat y) {
		mat ret;
		for(int i=0; i<x.n1; ++i){
			for(int j=0; j<y.n2; ++j){
				for(int k=0; k<x.n2; ++k){
					ret.a[i][j]=min(ret.a[i][j], x.a[i][k]+y.a[k][j]);
				}
			}
		}
		ret.n1=x.n1; ret.n2=y.n2;
		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], tt[N<<2], tag[N<<2], I, tem, bs;
int idx;
inline void push_up(int p){
	tt[p]=tt[p<<1|1]*tt[p<<1];
	tr[p]=(tr[p<<1|1]*tt[p<<1])+tr[p<<1];
}
inline void build(int p, int l, int r){
	tag[p]=I; tt[p]=I;
	if(l==r){
		tr[p].n1=1; tr[p].n2=4;
		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);
	push_up(p);
}
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*tt[p])+tr[p];
		return ;
	}
	int mid=(l+r)>>1;
	push_down(p);
	if(R>mid) qry(p<<1|1, mid+1, r, L, R);
	if(L<=mid) qry(p<<1, l, mid, 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);
	push_up(p);
}
inline void mdf2(int p, int l, int r, int x){
	if(l==r){
		tt[p]=tem;
		return ;
	}
	int mid=(l+r)>>1;
	push_down(p);
	if(x<=mid) mdf2(p<<1, l, mid, x);
	else mdf2(p<<1|1, mid+1, r, x);
	push_up(p);
}
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);
	push_up(p);
}
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, 0, n+1);
	for(int _=n; _>=0; --_){
		int i=rka[_];
		tem=bs; tem.n1=1; tem.n2=4;
		qry(1, 0, n+1, py[i]+1, n+1);
		st(1, 0, 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;
		mdf2(1, 0, n+1, py[i]);
		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, 0, n+1, 0, py[i]);
	}
	tem=bs; tem.n1=1; tem.n2=4;
	qry(1, 0, n+1, 0, n+1);
	ll ans=inf;
	for(int i=0; i<4; ++i) ans=min(ans, tem.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: 12ms
memory: 322712kb

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: 31ms
memory: 322596kb

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: 0
Accepted
time: 1789ms
memory: 327268kb

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:

154816494865

result:

ok single line: '154816494865'

Test #4:

score: 0
Accepted
time: 1521ms
memory: 327340kb

input:

200000
97216869 743886950 33071099 93740214 165915739 714765240 770423425 498199793 631193672 753722174 569396548 842251035 911607641 450531347 765200530 739362614 91640365 174209387 248940417 335559443 238573490 479206903 882783448 200485674 717481029 526848873 692757023 616376164 573933118 2566387...

output:

49954742111708

result:

ok single line: '49954742111708'

Test #5:

score: 0
Accepted
time: 1460ms
memory: 327272kb

input:

200000
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000...

output:

100000000000000

result:

ok single line: '100000000000000'

Test #6:

score: 0
Accepted
time: 1572ms
memory: 327344kb

input:

200000
274771488 823198191 332419028 866914185 137030479 445861162 505221814 805396419 842179806 540452002 510333908 765762441 345734318 975440944 186438657 676989478 108190396 339715111 337119327 462480232 634226928 438891079 609658471 156142766 16523966 699505629 190085420 960768051 824783291 5029...

output:

49967269431852

result:

ok single line: '49967269431852'

Test #7:

score: -100
Time Limit Exceeded

input:

200000
543681210 962563205 250397700 268525543 975554886 624102999 997517472 902158917 972202292 861887640 35775032 260723190 581651070 908449029 920192222 562166727 71415077 442629695 247231608 726904965 155868789 579129175 301712168 760082974 11645034 552993020 532073045 440207656 810726266 150259...

output:


result: