UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#204957#3643. BOccDreamer1005871ms108856kbC++114.1kb2024-06-16 10:42:162024-06-16 13:52:58

answer

//OccDreamer
#include<bits/stdc++.h>

#define vc vector
#define db double
#define fi first
#define se second
#define ll long long
#define mk make_pair
#define pb push_back
#define RI register int
#define PI pair<int,int>
#define ull unsigned long long
#define err cerr << "   -_-   " << endl
#define debug cerr << " ------------------- " << endl

#define input(x) freopen(#x".in","r",stdin)
#define output(x) freopen(#x".out","w",stdout)

#define NO puts("No")
#define YES puts("Yes")

//#define OccDreamer
#define int long long

using namespace std;

namespace IO{
	inline int read(){
		int X=0, W=0; char ch=getchar();
		while(!isdigit(ch)) W|=ch=='-', ch=getchar();
		while(isdigit(ch)) X=(X<<1)+(X<<3)+(ch^48), ch=getchar();
		return W?-X:X;
	}
	inline void write(int x){
		if(x<0) x=-x, putchar('-');
		if(x>9) write(x/10);
		putchar(x%10+'0');
	}
	inline void sprint(int x){write(x), putchar(32);}
	inline void eprint(int x){write(x), putchar(10);}
}using namespace IO;

const int MAXN = 2e5+5;
const int inf = 1e9;

int n, m, k, l, a[MAXN], b[MAXN], nodecnt, tot;
int root, lc[MAXN*33], rc[MAXN*33], maxn[MAXN*33], val[MAXN<<2];

map<int,int> dp;

inline int ask(int now, int l, int r, int L, int R){
	if(!now) return 0;
	if(L<=l && r<=R) return maxn[now];
	int mid=(l+r)>>1, res=0;
	if(L<=mid) res=max(res,ask(lc[now],l,mid,L,R));
	if(R>mid) res=max(res,ask(rc[now],mid+1,r,L,R));
	return res;
}

inline void upd(int &now, int l, int r, int pos, int v){
	if(!now) now=++nodecnt, lc[now]=rc[now]=maxn[now]=0;
	if(l==r) return maxn[now]=v, void();
	int mid=(l+r)>>1;
	pos<=mid?upd(lc[now],l,mid,pos,v):upd(rc[now],mid+1,r,pos,v);
	return maxn[now]=max(maxn[lc[now]],maxn[rc[now]]), void();
}

inline void pushup(int p){
	val[p]=max(val[p<<1],val[p<<1|1]);
	return ;	
}

inline void build(int p, int l, int r){
	if(l==r) return val[p]=dp[b[l]], void();
	int mid=(l+r)>>1;
	build(p<<1,l,mid); build(p<<1|1,mid+1,r);
	return pushup(p);	
}

inline int query(int p, int l, int r, int L, int R){
	if(L>R) return 0; 
	if(L<=l && r<=R) return val[p];
	int mid=(l+r)>>1, res=0;
	if(L<=mid) res=max(res,query(p<<1,l,mid,L,R));
	if(R>mid) res=max(res,query(p<<1|1,mid+1,r,L,R));
	return res;
}

int maxval, node, all;

vc<int> posv[MAXN<<2];

inline void getpos(int p, int l, int r, int L, int R, int v, int idx){
	if(val[p]<v || L>R) return ;
	if(L<=l && r<=R){
		if(l==r) return posv[idx].pb(b[l]), void();
		int mid=(l+r)>>1;
		getpos(p<<1,l,mid,L,R,v,idx); getpos(p<<1|1,mid+1,r,L,R,v,idx);
		return ;
	}
	int mid=(l+r)>>1;
	if(L<=mid) getpos(p<<1,l,mid,L,R,v,idx);
	if(R>mid) getpos(p<<1|1,mid+1,r,L,R,v,idx);
	return ;
}

inline void Query(int idx, int l, int r){
	posv[idx].clear(); posv[idx].shrink_to_fit();
	l=lower_bound(b+1,b+1+(tot+1),l)-b; r=upper_bound(b+1,b+1+(tot+1),r)-b-1;
	if(l>r) maxval=0;
	else{
		maxval=query(1,1,tot,l,r);
		getpos(1,1,tot,l,r,maxval,idx);
	}
}	

inline ll solve(int L, int R, int l, int r, int las){
	if(l>r) return 0;
	int idx=++node; Query(idx,l,r); int w=maxval;
	int cl, cr;
	if(L) cl=l+k;
	else cl=l;
	if(R) cr=r-k;
	else cr=r;
	if(maxval==0){
		if(cl<=cr){
			int c=(cr-cl)/(k+1)+1;
			return 1ll*c*las;
		}
		return 0;
	}
	ll Add;
	if(cl>cr) Add=0;
	else Add=1ll*(las-w)*((cr-cl)/(k+1)+1);
	PI stateL=mk(l,L);
	for(auto i:posv[idx]){
		Add+=solve(stateL.se,1,stateL.fi,i-1,w);
		stateL=mk(i+1,1);	
	}
	Add+=solve(stateL.se,R,stateL.fi,r,w);
	return Add;
}

inline void solve(){
	dp.clear(); int val; 
	root=0; node=0; nodecnt=0;
	n=read(), m=read(), k=read(), l=read();
	if(n==0){
		int c=(m-1)/(k+1)+1;
		return eprint(1ll*c*l), void();
	}
	for(int i=1;i<=n;++i){
		a[i]=read(), val=ask(root,1,m,max(a[i]-k,1ll),min(a[i]+k,m))+1;
		upd(root,1,m,a[i],val); dp[a[i]]=val, b[i]=a[i];
	}
	sort(b+1,b+1+n); tot=unique(b+1,b+1+n)-b-1; build(1,1,tot);	b[tot+1]=2e9;
	eprint(solve(0,0,1,m,l)+n);
}

signed main(){
	int t=read();
	while(t--) solve();
	return 0;
}



















































Details

小提示:点击横条可展开更详细的信息

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 207ms
memory: 19984kb

input:

20000
10 1000000000 1000000000 1000000000
226659035 250054074 546576995 203093961 170837339 20860008...

output:

1000000000
1000000000
1000000000
1000000000
1000000000
1000000000
1000000000
1000000000
1000000000
1...

result:

ok 20000 numbers

Test #2:

score: 0
Accepted
time: 585ms
memory: 108852kb

input:

1
200000 1000000000 1000000000 1000000000
992449362 651860722 269632286 716245558 965251943 31661828...

output:

1000000000

result:

ok 1 number(s): "1000000000"

Subtask #2:

score: 5
Accepted

Test #3:

score: 5
Accepted
time: 130ms
memory: 19984kb

input:

20000
10 1000000000 0 1000000000
246183521 96198515 305798977 625503123 211932925 163211461 15744794...

output:

1000000000000000000
1000000000000000000
1000000000000000000
1000000000000000000
1000000000000000000
...

result:

ok 20000 numbers

Test #4:

score: 0
Accepted
time: 511ms
memory: 104368kb

input:

1
200000 1000000000 0 1000000000
600021167 265035305 374864967 680233689 752439987 270740797 8326820...

output:

1000000000000000000

result:

ok 1 number(s): "1000000000000000000"

Subtask #3:

score: 10
Accepted

Test #5:

score: 10
Accepted
time: 69ms
memory: 19896kb

input:

200000
0 1000000000 3 1000000000
0 1000000000 3 1000000000
0 1000000000 3 1000000000
0 1000000000 3 ...

output:

250000000000000000
250000000000000000
250000000000000000
250000000000000000
250000000000000000
25000...

result:

ok 200000 numbers

Test #6:

score: 0
Accepted
time: 93ms
memory: 19892kb

input:

200000
0 1000000000 100 1000000000
0 1000000000 100 1000000000
0 1000000000 100 1000000000
0 1000000...

output:

9900991000000000
9900991000000000
9900991000000000
9900991000000000
9900991000000000
990099100000000...

result:

ok 200000 numbers

Test #7:

score: 0
Accepted
time: 78ms
memory: 19896kb

input:

200000
0 1000000000 100000 1000000000
0 1000000000 100000 1000000000
0 1000000000 100000 1000000000
...

output:

10000000000000
10000000000000
10000000000000
10000000000000
10000000000000
10000000000000
1000000000...

result:

ok 200000 numbers

Test #8:

score: 0
Accepted
time: 76ms
memory: 19892kb

input:

200000
0 1000000000 1000000 1000000000
0 1000000000 1000000 1000000000
0 1000000000 1000000 10000000...

output:

1000000000000
1000000000000
1000000000000
1000000000000
1000000000000
1000000000000
1000000000000
10...

result:

ok 200000 numbers

Subtask #4:

score: 15
Accepted

Test #9:

score: 15
Accepted
time: 193ms
memory: 19968kb

input:

200000
1 1000000000 3 1000000000
813113588
1 1000000000 3 1000000000
162432886
1 1000000000 3 100000...

output:

250000000000000000
250000000000000000
250000000000000000
250000000000000000
250000000000000000
25000...

result:

ok 200000 numbers

Test #10:

score: 0
Accepted
time: 210ms
memory: 19972kb

input:

200000
1 1000000000 100 1000000000
65059908
1 1000000000 100 1000000000
780925625
1 1000000000 100 1...

output:

9900990999999999
9900990999999999
9900990999999999
9900990999999999
9900990999999999
990099100000000...

result:

ok 200000 numbers

Test #11:

score: 0
Accepted
time: 211ms
memory: 19972kb

input:

200000
1 1000000000 100000 1000000000
310169056
1 1000000000 100000 1000000000
130497483
1 100000000...

output:

10000000000000
9999999999999
10000000000000
10000000000000
10000000000000
10000000000000
10000000000...

result:

ok 200000 numbers

Test #12:

score: 0
Accepted
time: 186ms
memory: 19968kb

input:

200000
1 1000000000 1000000 1000000000
42196964
1 1000000000 1000000 1000000000
116096811
1 10000000...

output:

1000000000000
1000000000000
1000000000000
1000000000000
1000000000000
1000000000000
1000000000000
10...

result:

ok 200000 numbers

Subtask #5:

score: 30
Accepted

Test #13:

score: 30
Accepted
time: 9ms
memory: 19988kb

input:

300
10 10 3 10
6 7 5 1 7 6 4 8 8 7
10 10 3 10
6 7 10 10 9 3 3 3 5 6
10 10 3 10
8 1 4 2 4 6 6 4 3 5
1...

output:

18
25
22
24
19
24
23
23
19
25
20
21
25
25
17
24
24
19
24
26
18
26
24
22
26
24
23
25
23
25
19
25
20
2...

result:

ok 300 numbers

Test #14:

score: 0
Accepted
time: 0ms
memory: 19984kb

input:

300
10 10 4 10
3 9 3 9 7 2 10 4 9 5
10 10 4 10
3 7 8 8 2 5 8 9 5 2
10 10 4 10
7 10 10 2 8 2 7 6 9 10...

output:

19
14
20
13
19
16
19
20
18
17
17
15
18
13
17
15
16
14
15
16
19
19
13
15
14
13
18
19
15
16
15
18
18
1...

result:

ok 300 numbers

Test #15:

score: 0
Accepted
time: 3ms
memory: 19992kb

input:

30
100 100 30 100
11 97 61 92 62 96 1 14 97 94 98 1 70 77 58 42 51 34 24 16 98 1 21 74 79 65 87 24 9...

output:

249
263
255
278
258
284
267
256
265
285
259
231
249
307
261
262
250
289
272
262
282
253
267
250
280
...

result:

ok 30 numbers

Test #16:

score: 0
Accepted
time: 7ms
memory: 19996kb

input:

30
100 100 13 100
81 75 72 3 50 68 39 54 15 25 64 22 39 61 40 71 58 76 68 17 35 32 18 9 60 30 52 71 ...

output:

634
658
671
696
680
672
675
649
668
613
613
660
657
654
671
651
648
593
639
655
617
665
666
656
687
...

result:

ok 30 numbers

Test #17:

score: 0
Accepted
time: 3ms
memory: 20344kb

input:

1
3000 3000 121 3000
1594 2003 742 1589 318 301 1116 1085 2883 180 2522 1755 1722 781 2082 712 887 2...

output:

70042

result:

ok 1 number(s): "70042"

Test #18:

score: 0
Accepted
time: 0ms
memory: 20344kb

input:

1
3000 3000 2987 3000
2467 1579 998 1618 1357 2165 1926 860 1375 1176 52 268 1860 2873 1418 2470 66 ...

output:

3000

result:

ok 1 number(s): "3000"

Subtask #6:

score: 35
Accepted

Test #19:

score: 35
Accepted
time: 133ms
memory: 19988kb

input:

20000
10 1000000000 3 1000000000
579022231 974160358 916238000 335408245 905609147 18568878 94851631...

output:

249999999999999997
249999999999999996
249999999999999997
249999999999999996
249999999999999996
24999...

result:

ok 20000 numbers

Test #20:

score: 0
Accepted
time: 129ms
memory: 19984kb

input:

20000
10 1000000000 4 1000000000
592826245 78674384 405780822 141131769 582921763 650893783 35034114...

output:

199999999999999996
199999999999999997
199999999999999997
199999999999999998
199999999999999996
19999...

result:

ok 20000 numbers

Test #21:

score: 0
Accepted
time: 142ms
memory: 20056kb

input:

2000
100 1000000000 30 1000000000
706959573 917853556 339926158 407774192 279323674 960270530 748240...

output:

32258064999999955
32258064999999953
32258064999999951
32258064999999957
32258064999999951
3225806499...

result:

ok 2000 numbers

Test #22:

score: 0
Accepted
time: 145ms
memory: 20052kb

input:

2000
100 1000000000 13 1000000000
467549977 585965482 521809854 595741967 458729064 95285208 2663221...

output:

71428571999999955
71428571999999955
71428571999999956
71428571999999950
71428571999999953
7142857199...

result:

ok 2000 numbers

Test #23:

score: 0
Accepted
time: 526ms
memory: 60664kb

input:

1
200000 1000000 121 1000000000
891005 278822 654128 505498 208457 970237 141411 104733 391594 92964...

output:

8196999698403

result:

ok 1 number(s): "8196999698403"

Test #24:

score: 0
Accepted
time: 542ms
memory: 105356kb

input:

1
200000 999976568 1210 1000000000
642090932 240890376 155277558 882428733 286350032 180672252 96799...

output:

825744999882269

result:

ok 1 number(s): "825744999882269"

Test #25:

score: 0
Accepted
time: 762ms
memory: 108856kb

input:

1
200000 999987679 1232131 1000000000
465561785 304303085 734834193 217572194 764029307 920399750 98...

output:

811999658121

result:

ok 1 number(s): "811999658121"

Test #26:

score: 0
Accepted
time: 921ms
memory: 108856kb

input:

1
200000 999576588 31031231 1000000000
349872441 576165215 659166910 621934286 226126614 746808809 6...

output:

32999613908

result:

ok 1 number(s): "32999613908"

Extra Test:

score: 0
Extra Test Passed