QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#600532#8200. Surowa zimaZpair100 ✓2994ms69056kbC++206.1kb2024-09-29 17:10:102024-09-29 17:10:10

Judging History

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

  • [2024-09-29 17:10:10]
  • 评测
  • 测评结果:100
  • 用时:2994ms
  • 内存:69056kb
  • [2024-09-29 17:10:10]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf=1e18;
const int N=250005;
void chkmin(ll &x,ll y){
	x=min(x,y);
}
ll k,L;
ll val(ll len){
	if(len<=k)return len;
	ll p=len/k,t=len-p*k;
	ll ans=(t+t+p*k)*(p+1);
	ans-=len;
	return ans;
}
ll v1(ll len){
	if(len<=k)return len;
	ll p=len/k,ans=inf,pos;
	pos=(p/2)*k,ans=val(pos)+val(len-pos+k)-k;
	pos=(p/2+1)*k,chkmin(ans,val(pos)+val(len-pos+k)-k);
	return ans;
}
ll v2(ll len){
	if(len<=k)return len*2;
	ll p=len/k,ans=inf,pos;
	pos=(p/2)*k,ans=val(pos)+val(len-pos)+len;
	pos=(p/2+1)*k,chkmin(ans,val(pos)+val(len-pos)+len);
	return ans;
}
ll v3(ll len){
	if(len==0)return 1e18;
	if(len<=k)return len;
	if(len<=2*k)return len+len-k;
	ll p=len/k,ans=inf,pos;
	pos=(p/2)*k,ans=val(pos)+val(len-pos)+min(pos,len-pos);
	pos=(p/2+1)*k,chkmin(ans,val(pos)+val(len-pos)+min(pos,len-pos));
	return ans;
}
int n;
mt19937 rnd(163337);
ll a1[N],a2[N],a3[N],a4[N],a5[N];
ll mn[N],mn2[N],s1[N],s2[N];
ll tag[N],tag2[N];
int pri[N],ls[N],rs[N],siz[N],rt,tot;
unordered_map<int, int> mp;
void update(int p){
	siz[p]=siz[ls[p]]+siz[rs[p]]+1;
	mn[p]=min({mn[ls[p]],mn[rs[p]],a4[p]});
	mn2[p]=min({mn2[ls[p]],mn2[rs[p]],a5[p]});
	s1[p]=s1[ls[p]]+s1[rs[p]]+a1[p];
	s2[p]=s2[ls[p]]+s2[rs[p]]+a2[p];
	mn[0]=mn2[0]=inf;
}
#define push(p,v) (a4[p]+=v,mn[p]+=v,tag[p]+=v)
#define push2(p,v) (a5[p]+=v,mn2[p]+=v,tag2[p]+=v)
void pushdown(int p){
	if(tag[p]){
		push(ls[p],tag[p]);
		push(rs[p],tag[p]);
		tag[p]=0;
	}
	if(tag2[p]){
		push2(ls[p],tag2[p]);
		push2(rs[p],tag2[p]);
		tag2[p]=0;
	}
}
void split(int p,int v,int &x,int &y){
	if(!p)return x=y=0,void();
	pushdown(p);
	if(siz[ls[p]]+1<=v)
		x=p,split(rs[p],v-siz[ls[p]]-1,rs[x],y);
	else y=p,split(ls[p],v,x,ls[y]);
	update(p);
}
int merge(int x,int y){
	if(!x||!y)return x|y;
	pushdown(x),pushdown(y);
	if(pri[x]<=pri[y]){
		rs[x]=merge(rs[x],y);
		update(x);
		return x;
	}
	else{
		ls[y]=merge(x,ls[y]);
		update(y);
		return y;
	}
}
ll _ans1,_ans2,_ans3,_ans4;
void ins(ll a1,ll a2,ll a3,ll a4){
	_ans1+=a1,_ans2+=a2;
	chkmin(_ans3,a3);
	chkmin(_ans4,a4);
}
void qry(int x,int y,int l,int r,int p){
	if(l<=x&&r>=y){
		ins(s1[p],s2[p],mn[p],mn2[p]);
		return;
	}
	pushdown(p);
	int mid=x+siz[ls[p]];
	if(l<=mid&&r>=mid)ins(a1[p],a2[p],a4[p],a5[p]);
	if(l<=mid-1)qry(x,mid-1,l,r,ls[p]);
	if(r>mid)qry(mid+1,y,l,r,rs[p]);
	//[x,mid-1] mid [mid+1,y]
}
set<ll> s,_s;//下标
ll xp[N],Sz;
void qry(int l,int r){
	_ans1=_ans2=0;
	_ans3=_ans4=inf;
	if(l>r)return;
	qry(1,siz[rt],l,r,rt);
}
void calc(int x,int y,int z,ll d){
	ll vv1=v1(d),vv2=v2(d);
	ll dt1=vv1-a1[y];
	ll dt2=vv2-a2[y];
	a4[y]-=a3[y];
	a5[y]-=a3[y];
	a1[y]=s1[y]=vv1;
	a2[y]=s2[y]=vv2;
	a3[y]=v3(d);
	a4[y]+=a3[y];
	a5[y]+=a3[y];
	mn[y]=a4[y];
	mn2[y]=a5[y];
	push(z,dt1);
	push(x,dt2);
	push2(z,dt2);
	push2(x,dt1);
}
void mdf(int i,ll d){
	int x,y,z,w;
	split(rt,i,w,z);
	split(w,i-1,x,y);
	//修改y
	calc(x,y,z,d);
	w=merge(x,y);
	rt=merge(w,z);
	//单点修改
}//将d[i]改为d
struct bit{
	#define lb(x) ((x)&(-(x)))
	int b[N];
	void add(int x,int v){
		for(;x<=n;x+=lb(x))
			b[x]+=v;
	}
	int qry(int x){
		int ans=0;
		for(;x;x-=lb(x))
			ans+=b[x];
		return ans;
	}
	#undef lb
}tree;
int findlst(int x){
	auto it=s.lower_bound(x);
	if(it==s.begin())return 0;
	else return *(--it);
}
int findnxt(int x){
	auto it=s.upper_bound(x);
	if(it==s.end())return n+1;
	else return *it;
}
int findlst2(int x){
	auto it=_s.lower_bound(x);
	if(it==_s.begin())return 0;
	else return mp[*(--it)];
}
int findnxt2(int x){
	auto it=_s.lower_bound(x);
	if(it==_s.end())return L+1;
	else return mp[*it];
}
vector<int> DEL;
void ins(int i){
	int lst=findlst(i),rk=0;
	int nxt=findnxt(i);
	ll d=(nxt==n+1?0ll:xp[nxt]-xp[i]);
	if(lst){
		rk=tree.qry(lst);
		ll d=xp[i]-xp[lst];
		mdf(rk,d);
	}
	int x,y,p;
	if(DEL.size()){
		p=DEL.back();
		DEL.pop_back();
		ls[p]=rs[p]=tag[p]=0;
	}
	else p=++tot;
	qry(1,rk);
	ll As1=_ans1,As2=_ans2;
	qry(rk+1,Sz-1);
	ll Bs1=_ans1,Bs2=_ans2;
	pri[p]=rnd();
	siz[p]=1;
	a1[p]=s1[p]=0;
	a2[p]=s2[p]=0;
	a3[p]=1e18;
	a4[p]=mn[p]=Bs2+As1+a3[p];
	a5[p]=mn2[p]=As2+Bs1+a3[p];
	split(rt,rk,x,y);
	calc(x,p,y,d);
	x=merge(x,p);
	rt=merge(x,y);
	s.insert(i);
	_s.insert(xp[i]);
	tree.add(i,1);
	Sz++;
}
void del(int i){
	int lst=findlst(i),rk=0;
	int nxt=findnxt(i);
	if(lst){
		rk=tree.qry(lst);
		ll d=(nxt==n+1?0:xp[nxt]-xp[lst]);
		mdf(rk,d);
	}
	rk++;
	int x,y,z,w;
	split(rt,rk,w,z);
	split(w,rk-1,x,y);
	calc(x,y,z,0);
	rt=merge(x,z);
	DEL.push_back(y);
	s.erase(i);
	_s.erase(xp[i]);
	tree.add(i,-1);
    Sz--;
}
ll solve(int i){
	int rk=tree.qry(i);
	ll Ld=*(_s.begin()),Rd=L-*(--_s.end());
	qry(1,rk-1);
	ll As1=_ans1,As2=_ans2,As3=_ans3,As4=_ans4;
	qry(rk,Sz-1);
	ll Bs1=_ans1,Bs2=_ans2,Bs3=_ans3,Bs4=_ans4;
	ll vLd=val(Ld),vRd=val(Rd);
	ll ret1=vLd+Ld+As2;
	ll ret2=vRd+Bs1;
	ll ret3=vRd+Rd-As1+Bs3;
	ll ans=ret1+min(ret2,ret3);
	ret1=vRd+Rd+Bs2;
	ret2=vLd+As1;
	ret3=vLd+Ld-Bs1+As4;
	ans=min(ans,ret1+min(ret2,ret3));
	return ans;
}
ll work(int pos){
	ll ans=inf;
	int lst=findlst2(pos);
	if(lst)ans=min(ans,solve(lst)+pos-xp[lst]);
	int nxt=findnxt2(pos);
	if(nxt!=L+1)ans=min(ans,solve(nxt)+xp[nxt]-pos);
	return ans;
}
int Q;
namespace IO
{
	#define gc()(xS==xTT&&(xTT=(xS=xB)+fread(xB,1,1<<20,stdin),xS==xTT)?0:*xS++)
	#define pc(x)(p3-obuf<1000000)?(*p3++=x):(fwrite(obuf,p3-obuf,1,stdout),p3=obuf,*p3++=x)
	char xch,xB[1<<20],*xS=xB,*xTT=xB,obuf[1000000],*p3=obuf;
	inline ll read()
	{
		char ch=gc();ll x=0,f=1;
		while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=gc();}
		while('0'<=ch&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=gc();}
		return x*f;
	}
}
using IO::read;
int main(){
	mn[0]=inf;
	mn2[0]=inf;
	cin>>n>>L>>k>>Q;ll x;
	for(int i=1;i<=n;++i){
		x=read();
		xp[i]=x;
		mp[x]=i;
	}
	for(int i=1;i<=n;++i)
		ins(i);
	while(Q--){
		int z,u,p,x;
		z=read(),u=read(),p=read();
		for(int i=1;i<=z;++i)
			x=read(),ins(x);
		for(int i=1;i<=u;++i)
			x=read(),del(x);
		printf("%lld\n",work(p));
	}
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 0ms
memory: 30628kb

input:

9 9 2 43
1 2 3 4 5 6 7 8 9
0 0 9


0 0 2


0 0 0


0 5 3

1 3 5 8 9
0 1 0

6
0 0 8


0 0 0


1 0 0
6

0 0 4


0 2 0

2 6
0 0 9


1 0 0
2

0 0 0


0 1 1

2
2 0 2
2 6

0 0 2


0 1 9

6
0 0 2


1 0 0
6

2 0 7
1 8

0 1 7

8
0 0 3


1 0 3
8

0 0 1


0 2 0

1 8
2 0 3
1 8

0 0 4


0 0 3


0 2 6

1 8
0 0 5
...

output:

9
11
11
12
15
14
15
13
13
22
19
15
15
21
11
11
15
13
13
11
11
12
12
10
13
12
13
12
12
13
11
11
12
11
12
11
11
11
11
12
12
12
11

result:

ok 43 lines

Test #2:

score: 10
Accepted
time: 0ms
memory: 32436kb

input:

10 11 3 42
1 2 3 5 6 7 8 9 10 11
0 0 6


0 0 10


0 7 2

1 3 4 6 7 8 10
2 3 0
4 7
2 5 9
4 2 4
2 3 5 8
4 7
0 2 1

3 8
2 2 11
4 6
2 5
2 1 5
3 8
6
2 1 10
1 7
3
2 4 10
3 6
1 4 7 8
4 2 3
1 4 5 8
3 6
1 2 4
3
1 4
1 2 0
2
3 8
2 2 10
3 6
2 5
2 2 2
1 5
3 6
3 2 7
3 4 6
1 5
2 2 0
2 9
3 4
4 3 4
3 4 7 8
2 6 9
3 1...

output:

16
12
17
25
15
20
25
17
16
22
16
15
21
22
21
17
19
15
13
13
16
16
16
15
15
14
16
16
13
14
13
13
13
12
13
15
16
14
13
15
13
16

result:

ok 42 lines

Test #3:

score: 10
Accepted
time: 2ms
memory: 32376kb

input:

11 11 1 42
1 2 3 4 5 6 7 8 9 10 11
0 0 6


0 0 3


0 7 10

1 3 4 6 8 9 11
3 3 9
3 6 9
2 5 10
4 4 0
2 4 5 8
3 6 7 9
2 1 1
6 10
4
3 3 6
4 7 9
5 8 10
1 1 1
1
2
3 4 11
3 5 8
1 6 7 9
2 2 10
2 9
3 4
4 4 9
3 4 7 10
2 5 8 9
3 3 1
1 5 8
3 7 10
3 3 1
3 7 10
1 5 8
3 2 5
2 6 9
3 10
3 3 6
1 3 8
2 6 9
2 3 0
6 10
...

output:

16
14
24
27
29
24
23
22
33
26
27
26
30
24
27
30
28
20
18
19
19
22
21
21
23
19
19
21
23
21
22
21
17
20
15
17
16
17
16
17
18
17

result:

ok 42 lines

Test #4:

score: 10
Accepted
time: 0ms
memory: 30412kb

input:

12 12 3 42
1 2 3 4 5 6 7 8 9 10 11 12
0 0 1


0 0 10


0 8 2

1 2 4 6 7 10 11 12
2 2 10
4 7
5 8
1 2 7
5
4 7
4 3 7
2 6 8 10
3 5 9
3 4 4
4 7 9
2 6 8 10
3 2 5
2 5 6
4 7
1 1 3
3
5
1 2 10
7
3 6
1 1 2
4
2
2 1 3
3 11
4
2 2 12
6 8
7 11
3 3 2
2 4 10
3 8 9
3 3 9
5 7 9
4 6 10
3 3 10
1 8 10
2 7 9
2 3 11
2 9
1 8...

output:

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

result:

ok 42 lines

Test #5:

score: 10
Accepted
time: 2ms
memory: 32372kb

input:

6 12 4 38
2 3 6 9 10 12
0 0 9


0 0 2


0 5 5

1 2 4 5 6
0 0 8


1 1 11
4
3
0 0 11


1 1 12
3
4
2 1 5
2 4
3
1 2 0
3
2 4
2 1 8
2 4
3
0 0 1


0 0 12


2 1 9
3 5
4
0 1 5

2
2 1 11
2 4
5
1 2 11
5
2 4
1 0 8
2

0 1 0

5
1 1 2
4
3
3 2 2
1 3 5
2 4
1 2 1
2
1 5
1 1 9
5
3
1 0 0
4

1 0 6
1

1 1 8
3
1
0 1 12

5
...

output:

15
14
27
28
29
29
32
21
32
20
21
22
15
23
17
19
16
22
20
14
21
21
22
22
16
18
14
18
18
17
18
16
15
21
17
19
16
15

result:

ok 38 lines

Test #6:

score: 10
Accepted
time: 0ms
memory: 30324kb

input:

12 12 1 44
1 2 3 4 5 6 7 8 9 10 11 12
0 0 10


0 0 1


0 0 0


0 0 12


0 5 8

1 3 6 11 12
1 2 0
3
2 4
5 4 7
1 2 4 6 11
3 5 7 9
2 2 5
7 9
8 11
3 3 7
3 5 8
2 4 7
2 3 4
4 7
1 6 8
2 1 5
2 6
5
3 3 7
1 5 8
3 4 6
3 4 12
3 6 11
1 2 8 10
4 3 4
2 4 8 10
5 7 11
2 3 12
5 7
4 6 8
4 4 0
4 6 8 11
3 5 7 9
2 2 10
5...

output:

14
13
14
12
24
30
23
23
23
28
25
23
26
24
26
26
24
25
26
24
21
23
23
21
30
23
21
22
23
22
22
25
26
24
16
19
20
18
17
21
14
17
18
14

result:

ok 44 lines

Subtask #2:

score: 12
Accepted

Test #7:

score: 12
Accepted
time: 5ms
memory: 32484kb

input:

250 495 1 50
1 2 3 4 8 12 13 16 17 20 21 24 25 27 28 29 30 33 36 39 40 43 44 47 48 51 52 53 55 57 60 62 65 68 70 72 73 75 77 78 80 82 85 87 90 93 94 96 99 101 103 106 109 112 114 116 117 118 121 123 124 127 129 130 132 133 136 138 139 142 144 145 147 150 152 153 154 157 160 162 163 166 168 170 171 1...

output:

1662
1701
1708
1701
1696
1689
1664
1698
1680
1691
1651
1732
1737
1712
1710
1678
1679
1654
1706
1726
2119
2037
7588
2302
7844
2256
8704
5972
7280
16262
6302
2025
7145
2574
6008
4122
5402
6952
2573
7779
2936
3151
2918
3028
2938
3146
3119
2956
3132
2978

result:

ok 50 lines

Test #8:

score: 12
Accepted
time: 0ms
memory: 32684kb

input:

215 486 1 50
1 6 7 10 12 17 18 19 20 25 28 30 32 34 40 42 44 45 50 53 55 58 61 64 68 69 70 71 72 77 78 79 82 87 88 90 94 95 97 98 99 103 104 105 107 110 111 115 117 119 122 123 126 130 132 133 134 138 139 141 143 147 149 150 153 155 158 160 163 164 166 170 173 175 176 177 181 182 183 184 189 193 198...

output:

8826
2599
4103
3803
7589
2534
10366
3523
2720
2472
3014
4320
9690
13523
8905
4380
3815
4006
6326
3190
4356
6779
4048
13163
3264
3401
3666
5740
8310
2741
3317
3330
2769
2718
3223
3098
2631
4421
2501
4010
5657
4605
2815
3827
3045
2496
2220
2246
2222
2213

result:

ok 50 lines

Test #9:

score: 12
Accepted
time: 9ms
memory: 30508kb

input:

501 500 1 50
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 ...

output:

5638
5784
5860
5998
5833
3198
2975
2920
3044
2945
3041
2805
3263
2936
3130
1707
1728
1725
1704
1722
1722
1775
1632
1739
1704
1777
1732
1657
1740
1718
1001
1034
1028
1034
1048
1048
1022
1060
1053
1044
1033
1041
1063
1026
1023
1055
993
1008
1000
1051

result:

ok 50 lines

Test #10:

score: 12
Accepted
time: 3ms
memory: 30296kb

input:

154 254 1 50
0 1 3 4 6 7 8 10 14 16 17 18 22 23 24 25 29 30 32 34 35 37 39 40 43 45 46 49 51 53 54 57 59 61 62 65 66 68 69 70 71 73 74 75 76 77 78 80 83 84 85 86 87 89 90 92 94 96 98 99 101 103 104 107 108 109 110 111 113 114 115 116 119 120 121 123 126 127 128 129 130 131 132 135 136 137 140 143 14...

output:

1574
3625
1071
851
1397
941
963
1057
1179
1092
1019
778
564
823
4271
1101
5589
939
1592
2132
870
1720
1034
973
908
829
854
7308
1142
1123
558
745
832
3200
1896
1277
1635
1233
3769
1582
1134
945
970
1817
3548
938
1978
1041
578
692

result:

ok 50 lines

Test #11:

score: 12
Accepted
time: 0ms
memory: 32384kb

input:

122 499 1 50
3 9 13 16 19 26 34 37 44 45 46 53 57 58 63 65 67 75 77 85 86 89 91 99 103 105 114 117 121 129 132 140 144 148 149 155 156 161 163 170 171 177 179 182 186 194 196 204 208 218 221 224 232 234 244 249 250 259 261 264 266 274 280 281 287 288 295 296 297 298 304 311 315 320 321 326 327 338 3...

output:

6427
4420
7383
14379
5764
4905
6661
10899
4817
6096
4818
4143
13635
5402
12611
9245
4300
3797
5594
10894
3602
12452
4749
3982
6775
17979
9097
6593
4358
4329
14162
5434
10443
6268
8436
6634
6237
5230
5322
11518
6206
5970
7878
6892
9440
6923
5411
5555
11674
18100

result:

ok 50 lines

Subtask #3:

score: 8
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Test #12:

score: 8
Accepted
time: 229ms
memory: 34276kb

input:

25000 5000000 51 20
112 435 582 902 1243 1480 1829 1863 2090 2487 2707 2994 3168 3450 3532 3630 3976 4311 4566 4962 5176 5427 5739 5811 5921 5924 6175 6465 6593 6894 7043 7430 7816 8002 8186 8336 8679 9003 9026 9251 9548 9867 9976 10018 10254 10520 10853 11146 11524 11840 12122 12376 12525 12790 130...

output:

42856586
1453488037
970197028
52487076
51076661
48739581
56106078
72073047
1955675648
48849040
55644243
1496260500
57184400
1255346927
1871581846
46873584
3068277745
1421560187
59614895
901893228

result:

ok 20 lines

Test #13:

score: 8
Accepted
time: 1375ms
memory: 68368kb

input:

250000 5000000 10 20
28 46 76 108 117 134 168 203 219 231 235 252 264 293 297 314 349 359 380 414 436 455 477 516 529 531 552 576 597 632 649 689 718 735 769 783 823 824 845 869 898 916 935 940 967 990 1013 1040 1067 1099 1135 1174 1182 1186 1225 1262 1263 1303 1304 1314 1315 1355 1358 1388 1399 143...

output:

37955032
36261589
1719134274
39997915
3813597180
4694716047
3264383751
44372337
12033482042
23930020937
2883362389
53100687
2752707044
7027872083
25527692184
20063774853
3769998256
11123023000
54738204
40071482

result:

ok 20 lines

Test #14:

score: 8
Accepted
time: 1152ms
memory: 67956kb

input:

246396 5000000 5 20
8 61 75 97 120 125 126 127 137 194 201 209 231 249 262 286 304 321 342 364 383 406 420 431 491 503 532 554 561 600 602 631 632 634 696 703 734 736 756 791 798 842 846 869 872 900 903 922 943 968 987 1024 1028 1057 1078 1081 1106 1158 1168 1171 1187 1206 1251 1276 1283 1297 1304 1...

output:

593868318
421137343
223469439
765603328
1266416571
561810551
319530899
220377325
173163100
144437662
366985426
250417460
1173744637
167321436
138337575
562071863
317593051
221323360
1224004774
1488229388

result:

ok 20 lines

Test #15:

score: 8
Accepted
time: 816ms
memory: 51196kb

input:

131072 5000000 263 20
38 104 168 191 199 260 291 357 393 396 420 421 497 568 597 599 622 687 695 741 785 844 869 919 931 993 1010 1020 1049 1051 1073 1113 1169 1184 1200 1269 1337 1376 1413 1468 1483 1553 1621 1643 1651 1652 1702 1748 1749 1754 1810 1843 1860 1911 1949 1975 2036 2088 2097 2101 2126 ...

output:

12771018
12691519
12983776
12778211
12949686
12811980
12774259
12731187
12777739
12932258
13036739
12942301
12687549
12723145
12872010
12810416
12584654
13053166
12802117
12830190

result:

ok 20 lines

Test #16:

score: 8
Accepted
time: 867ms
memory: 69056kb

input:

250000 5000000 1000000 20
3 32 52 82 102 127 152 168 186 211 236 266 305 318 353 361 365 387 395 433 436 464 485 514 531 541 571 591 612 635 671 687 699 724 747 748 773 811 836 872 908 931 950 973 997 1006 1041 1047 1086 1094 1102 1136 1143 1152 1186 1206 1229 1238 1264 1281 1282 1287 1327 1331 1344...

output:

6363302
7349809
5760187
6463706
5033167
5852222
6522141
7186079
5788774
6372685
5484031
6133837
5705361
5053883
6679155
6586834
6993221
6126016
6063754
6583865

result:

ok 20 lines

Subtask #4:

score: 8
Accepted

Test #17:

score: 8
Accepted
time: 790ms
memory: 50208kb

input:

131072 7000000 263 250000
20 22 45 99 158 245 288 360 437 450 462 563 615 629 669 748 823 894 984 1008 1097 1138 1150 1165 1225 1285 1391 1470 1486 1515 1611 1679 1717 1791 1847 1887 1958 2030 2095 2150 2191 2206 2244 2337 2418 2485 2547 2595 2649 2670 2769 2813 2914 2991 3041 3062 3168 3185 3280 33...

output:

8513356
8471871
8419347
7712212
8754163
9757890
9420391
8969598
10442369
10099473
8759883
7530068
7442310
9285306
10435831
9407102
8141129
8396502
7532797
7308905
8681626
7383619
9685899
9239374
9767102
9498756
9657515
9663700
7892842
8020437
8391769
8605798
8747139
7475189
9707930
7665595
9996277
1...

result:

ok 250000 lines

Test #18:

score: 8
Accepted
time: 1080ms
memory: 66548kb

input:

249902 100000000 11 250000
23 44 67 90 113 135 157 1005 2569 2591 2614 2636 2658 2681 2916 5093 5116 5137 5158 5179 5200 5307 7612 7634 7655 7677 7683 7700 7721 8407 10133 10155 10177 10198 10221 10242 11066 12654 12676 12698 12720 12742 12763 13781 14947 15175 15197 15218 15240 15262 15283 16949 17...

output:

6726630031
6726672457
6726711810
6726701654
6726552459
6726591802
6726452071
6726432906
6726473216
6726592308
6726571118
6726670585
6726534324
6726575900
6726472842
6726583045
6726503902
6726513331
6726670016
6726649284
6726494446
6726422443
6726500821
6726664808
6726538420
6726421183
6726531622
672...

result:

ok 250000 lines

Test #19:

score: 8
Accepted
time: 1033ms
memory: 65816kb

input:

241997 668000583 155 250000
311 621 931 1240 1549 1859 2168 2478 2787 3098 3409 3426 3719 4029 4338 4647 4956 5267 5576 5885 6194 6505 6816 7127 7436 7746 8057 8368 8678 8989 9300 9611 9922 10026 10231 10540 10851 11162 11472 11783 12092 12401 12712 13021 13332 13643 13953 14263 14574 14883 15192 15...

output:

14073835750
14074486724
14075450584
14075915328
14073036395
14072739392
14075168249
14073448303
14073247222
14074020395
14076450754
14076285085
14077140377
14072739441
14074189849
14074164911
14073590273
14072573130
14073257644
14075717045
14074254916
14075954652
14073451291
14074273261
14075974084
...

result:

ok 250000 lines

Test #20:

score: 8
Accepted
time: 1044ms
memory: 62036kb

input:

218094 835802697 51 250000
101 202 304 405 506 609 712 815 918 958 1059 1160 1262 1363 1465 1566 1669 1772 1857 1958 2059 2160 2241 2263 2364 2467 2568 2670 2880 2983 3084 3187 3288 3390 3493 3595 3696 3935 4036 4139 4240 4343 4445 4546 4647 4750 4851 4952 5054 5155 5258 5360 5718 5821 5924 6026 612...

output:

38459413997
38459453691
38458809528
38457622281
38457877840
38457827150
38457573899
38458874813
38457767288
38458767126
38458207137
38457801725
38459411964
38458736190
38459712079
38458213923
38459696090
38458766073
38458798296
38458678798
38457879738
38457686851
38457743144
38459368400
38458929572
...

result:

ok 250000 lines

Test #21:

score: 8
Accepted
time: 1064ms
memory: 66860kb

input:

250000 1000000000 10000 250000
1010 1965 7343 11625 19449 25096 31489 34459 35565 39097 42227 47368 50804 55367 58242 65278 67055 68342 69596 73709 73721 80363 84681 89730 93987 94668 96832 97851 98695 103725 108117 109860 116495 118023 122894 124064 124899 125487 133310 134651 141830 149231 152377 ...

output:

1346428598
1060481061
1415124008
1036274277
1248315636
1465191170
1385172527
1189554941
1215249414
1238806082
1020570268
1017498334
1406257303
1499335350
1064239075
1373288069
1379448384
1056035332
1403161409
1081345580
1157531517
1013676167
1346880747
1383131528
1415376255
1089459676
1144028672
101...

result:

ok 250000 lines

Subtask #5:

score: 20
Accepted

Test #22:

score: 20
Accepted
time: 2994ms
memory: 66660kb

input:

245189 984079106 32 250000
64 127 192 255 318 381 445 508 573 637 702 765 830 894 957 1021 1084 1147 1210 1273 1337 1402 1465 1530 1593 1657 1721 1784 1847 1911 1974 2038 2101 2164 2227 2292 2357 2422 2485 2507 2570 2633 2696 2761 2825 2890 2955 3019 3083 3147 3210 3274 3339 3404 3468 3532 3595 3660...

output:

359358894786
359358890346
359358715033
359358746197
359358807351
359358681261
359359101233
359358912570
359358869227
359358911384
359358691435
359358668872
359358539812
359376681536
359376609835
359376633013
359373538272
359393475124
359393692953
359393735508
359393659138
359393575272
359393700041
3...

result:

ok 250000 lines

Test #23:

score: 20
Accepted
time: 917ms
memory: 34700kb

input:

25000 1000000000 18 250000
39893 95753 140058 211204 262348 339921 356909 395028 457548 465948 470237 516362 573743 628363 693599 770068 784602 823576 877229 914629 969520 1037991 1110176 1177801 1229681 1281533 1351873 1391458 1469715 1522829 1585529 1633517 1698215 1711879 1777769 1786313 1812068 ...

output:

1495901528736
1495901528957
1496105924330
1496162396963
1496162414412
1496162517798
1496162440556
1496227644547
1496331116125
1497234941167
1497512482728
1498356679946
1498545818074
1498556575352
1498556553724
1498439782568
1498255368180
1498902629920
1498902572601
1498335933904
1499020911709
149874...

result:

ok 250000 lines

Test #24:

score: 20
Accepted
time: 2526ms
memory: 64624kb

input:

236093 967100586 10 250000
20 39 58 79 100 119 140 159 179 198 219 238 257 278 298 318 339 358 378 398 417 437 456 477 498 518 539 558 578 597 616 637 656 657 677 698 717 737 757 778 797 816 836 857 877 897 916 936 957 977 997 1016 1035 1056 1075 1094 1114 1135 1154 1199 1218 1237 1258 1278 1297 131...

output:

1109601408237
1109601558733
1109601413588
1109782741173
1109956934565
1109957015321
1109957025545
1109956905055
1110124011583
1110124071136
1110123897979
1110124025847
1110124005443
1110301190788
1110301231859
1110474750069
1110474588151
1110474603907
1110474704246
1110530708456
1110913781715
111091...

result:

ok 250000 lines

Test #25:

score: 20
Accepted
time: 727ms
memory: 66672kb

input:

249990 1000000000 24 2600
47 95 143 190 239 10343 25047 25095 25143 25190 25238 25286 25334 30159 49499 50142 50189 50237 50286 50334 69084 75142 75190 75239 89249 100047 100095 100144 100191 100240 109167 125048 125097 125146 125194 125241 125290 129521 150098 150145 150193 150798 170523 175001 175...

output:

303236936480
303465813658
303523422823
303981118233
303657482313
303652882734
304904510462
303652020492
304695886924
303634201703
303987860438
303733834732
303733229206
304003508628
304002297021
304236591136
304095699465
303936608051
304480990235
304355790657
304249212162
303506189097
303506214555
3...

result:

ok 2600 lines

Subtask #6:

score: 18
Accepted

Dependency #2:

100%
Accepted

Test #26:

score: 18
Accepted
time: 1464ms
memory: 34676kb

input:

30000 50000 1 250000
0 1 3 5 7 8 11 14 17 18 19 20 23 25 27 28 29 32 35 37 39 42 44 47 49 50 52 54 56 59 62 65 66 67 68 71 73 76 77 79 81 83 84 87 90 91 92 94 96 97 99 102 104 106 108 109 111 113 115 118 119 120 123 124 125 127 129 130 133 136 139 140 143 144 146 148 149 152 154 156 157 159 161 162 ...

output:

104291
103290
102872
103512
102827
98600
98034
98527
99791
99144
104428
102091
101115
103005
103923
98814
104847
102447
99815
101838
100527
105122
103635
101379
104062
101305
101183
99934
98472
98011
100488
102299
102111
101006
104621
99284
105264
103186
105143
99706
100193
99658
102790
105217
10191...

result:

ok 250000 lines

Test #27:

score: 18
Accepted
time: 2391ms
memory: 65592kb

input:

232955 208954842 1 250000
1 4 7 10 13 16 18 20 23 26 29 31 34 36 37 40 43 45 47 49 50 51 54 57 59 62 64 66 71 73 75 76 77 78 80 81 84 86 89 92 94 97 99 100 101 102 104 105 108 111 114 115 116 119 120 122 123 125 128 131 134 135 138 141 144 145 207 210 211 212 215 216 219 221 223 224 225 228 229 231 ...

output:

168384488524
168384492475
168384522273
168387308959
168387326053
168405386039
168405367439
168405371798
168405400283
168405409542
168405395389
168405370842
168407960657
168407979820
168407923937
168407930486
168407981792
168407967882
168407945488
168407929497
168422197654
168422228719
168422221651
1...

result:

ok 250000 lines

Test #28:

score: 18
Accepted
time: 2371ms
memory: 69000kb

input:

249999 1000000 1 250000
2 5 6 7 10 13 14 15 16 18 19 21 24 26 27 31 33 36 39 42 44 47 48 50 53 55 58 59 61 62 65 68 70 71 73 75 76 77 80 82 84 85 86 89 190 193 194 196 197 199 200 202 204 205 206 207 210 212 215 218 219 222 225 228 229 232 235 238 240 242 245 246 247 250 251 253 256 259 261 263 264 ...

output:

28463584
28496200
28467070
28468601
28489315
28466649
28481313
28488236
28471222
28467992
28488083
28474716
28483085
28497808
28485868
28481578
28471336
28485836
28477954
28462592
28497148
28465351
28473219
28464285
28497347
28498082
28466421
28489204
28486699
28484690
28485476
28468354
28472967
284...

result:

ok 250000 lines

Subtask #7:

score: 24
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Dependency #6:

100%
Accepted

Test #29:

score: 24
Accepted
time: 2278ms
memory: 68456kb

input:

250000 100000000 64 250000
765 1202 1976 2529 3027 3713 4009 4791 4922 5046 5341 6018 6544 7024 7594 7630 7937 8272 8841 9182 9319 9718 10387 10466 10857 11540 11690 12395 12649 13255 13390 14154 14718 15433 16146 16319 17044 17168 17367 17886 18289 19052 19105 19208 19866 20596 20978 21467 21857 22...

output:

616444644
617325240
618459525
617852429
615636736
616046980
615657082
616499594
616294611
616431078
616528645
616590380
615356268
617816613
616293671
618495124
617775714
617126367
617898503
617617543
616329569
615602658
617398313
618138372
616445920
616030506
615446929
618025115
617086289
617254048
...

result:

ok 250000 lines

Test #30:

score: 24
Accepted
time: 2230ms
memory: 68584kb

input:

249999 500000000 65 250000
130 259 388 517 646 777 906 1037 1166 1297 1426 1556 1686 1817 33113 33242 33371 33502 33633 33763 33893 34025 34156 34285 34414 34543 34672 34802 34932 35062 66358 66489 66618 66747 66878 67007 67137 67266 67396 67527 67658 67787 67916 68046 68176 68307 68436 68566 68696 ...

output:

114450038787
114450116870
114450197855
114450117848
114450212098
114450122050
114449947446
114450034184
114449971761
114450060450
114450019079
114450234649
114449970004
114449981407
114450177520
114450080123
114450152360
114450218475
114450235749
114449994721
114450107554
114450201949
114449974068
1...

result:

ok 250000 lines

Test #31:

score: 24
Accepted
time: 2758ms
memory: 67168kb

input:

241069 291520677 203 250000
406 811 1218 1625 1692 2030 2436 2842 3249 3656 4061 4468 4875 5280 5687 5962 6093 6498 6904 7311 7716 8121 8527 8934 9340 9745 10150 10533 10557 10964 11371 11777 12184 12590 12995 13402 13808 14215 14302 14621 15027 15433 15840 16246 16651 17057 17463 17870 18275 18514 ...

output:

2645836674
2646937058
2647122910
2644731952
2645917718
2646097422
2646946444
2646297360
2645389718
2649187007
2648112381
2645695424
2646591266
2647748021
2646618800
2647269833
2648565421
2647204629
2647990577
2648185975
2649673004
2649946119
2647427482
2647049931
2649112549
2646833704
2649450052
264...

result:

ok 250000 lines

Test #32:

score: 24
Accepted
time: 2838ms
memory: 67748kb

input:

244987 610676527 24 250000
48 96 145 193 240 287 335 383 432 481 529 578 626 673 720 768 815 862 911 960 1009 1057 1106 1155 1169 1217 1265 1312 1361 1409 1457 1506 1555 1602 1650 1657 1698 1746 1794 1841 1889 1937 1985 2032 2079 2128 2177 2224 2273 2322 2370 2418 2467 2516 2563 2655 2704 2751 2799 ...

output:

55925001738
55926684266
55933099516
55933352217
55934374075
55936103670
55936043100
55939429655
55940460123
55941434725
55942167300
55942748889
55942915319
55943610887
55945427859
55944931248
55946361432
55945964280
55946355621
55945789612
55947236592
55947233370
55951596379
55953703257
55953629353
...

result:

ok 250000 lines

Test #33:

score: 24
Accepted
time: 2521ms
memory: 53888kb

input:

150514 276817022 997 250000
1326 1993 2610 3988 5244 5981 7329 7976 8407 9969 10606 11962 13321 13955 14736 15948 17243 17942 19409 19936 20880 21931 22322 23926 24300 25919 26058 27912 28666 29907 31010 31900 32223 33893 34747 35886 36092 37879 38185 39872 40334 41867 41868 42222 43862 43973 45855 ...

output:

565227918
554690948
567066625
575407085
559273748
577202425
555123425
548445464
566041363
557109085
553927171
549249176
571914120
570799789
557595653
568645045
549776543
560076667
550740028
546845736
555722168
550053614
576966704
547216376
571945094
554535482
550974426
568037967
546146852
553844294
...

result:

ok 250000 lines

Test #34:

score: 24
Accepted
time: 538ms
memory: 66424kb

input:

250000 417957371 100007 250000
0 2 6 7 8 18 19 20 21 22 23 24 25 26 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199...

output:

291156224417
291182281046
291116594853
291125406037
291127357585
291122784413
291115395818
291136011181
291129702785
291138407163
291124953595
291185890002
291205866103
291125769848
291133322089
291193538119
291118452393
291118824174
291118226793
291208285408
291137010919
291143410217
291122139940
2...

result:

ok 250000 lines

Extra Test:

score: 0
Extra Test Passed