#include "ricehub.h"
#include<bits/stdc++.h>
using namespace std;
long long int typedef li;
//1-root obicnog, 2-root kurca
li val[10000007],L[10000007],R[10000007],idx=2;
void add(li p, li l, li r, li s, li x)
{
val[p]+=x;
if (l==r) return;
li mid=(l+r)/2;
if (s<=mid)
{
if (!L[p]) L[p]=++idx;
add(L[p],l,mid,s,x);
}
else
{
if (!R[p]) R[p]=++idx;
add(R[p],mid+1,r,s,x);
}
}
li sum(li p, li l, li r, li ll, li rr)
{
if (!p || ll>r || rr<l) return 0;
if (ll<=l && rr>=r) return val[p];
li mid=(l+r)/2;
return sum(L[p],l,mid,ll,rr)+sum(R[p],mid+1,r,ll,rr);
}
li walk(li p, li l, li r, li k)
{
if (l==r) return l;
li mid=(l+r)/2;
if (val[L[p]]>=k) return walk(L[p],l,mid,k);
return walk(R[p],mid+1,r,k-val[L[p]]);
}
li balans(li m)
{
if (m<=0) return 0;
li p=walk(1,1,1e18,m/2);
return ((li)sum(1,1,1e18,1,p)*p-(li)sum(2,1,1e18,1,p))+((li)sum(2,1,1e18,p,1e18)-(li)sum(1,1,1e18,p,1e18)*p);
}
int besthub(int n, int useless, int x[], li b)
{
li l=0,r=0,mx=0;
for (;r<n;r++)
{
add(1,1,1e18,x[r],1);
add(2,1,1e18,x[r],x[r]);
while (balans(r-l+2)>b) add(1,1,1e18,x[l],-1),add(2,1,1e18,x[l],-x[l]),l++;
//cout<<"["<<l<<","<<r<<"] - "<<balans(r-l+2)<<endl;
mx=max(mx,r-l+1);
}
return mx;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
468 KB |
Output is correct |
24 |
Correct |
2 ms |
468 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
2 ms |
468 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
3 ms |
852 KB |
Output is correct |
4 |
Correct |
3 ms |
852 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
4 ms |
352 KB |
Output is correct |
8 |
Correct |
4 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
3 ms |
340 KB |
Output is correct |
11 |
Correct |
4 ms |
468 KB |
Output is correct |
12 |
Correct |
4 ms |
468 KB |
Output is correct |
13 |
Correct |
2 ms |
468 KB |
Output is correct |
14 |
Correct |
2 ms |
468 KB |
Output is correct |
15 |
Correct |
2 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
468 KB |
Output is correct |
18 |
Correct |
2 ms |
468 KB |
Output is correct |
19 |
Correct |
3 ms |
852 KB |
Output is correct |
20 |
Correct |
3 ms |
852 KB |
Output is correct |
21 |
Correct |
20 ms |
368 KB |
Output is correct |
22 |
Correct |
19 ms |
468 KB |
Output is correct |
23 |
Correct |
11 ms |
852 KB |
Output is correct |
24 |
Correct |
13 ms |
784 KB |
Output is correct |
25 |
Correct |
14 ms |
2364 KB |
Output is correct |
26 |
Correct |
13 ms |
2340 KB |
Output is correct |
27 |
Correct |
16 ms |
2288 KB |
Output is correct |
28 |
Correct |
18 ms |
2260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
85 ms |
4404 KB |
Output is correct |
2 |
Correct |
87 ms |
4408 KB |
Output is correct |
3 |
Correct |
276 ms |
72452 KB |
Output is correct |
4 |
Correct |
271 ms |
72304 KB |
Output is correct |
5 |
Correct |
189 ms |
1340 KB |
Output is correct |
6 |
Correct |
185 ms |
1140 KB |
Output is correct |
7 |
Correct |
189 ms |
3740 KB |
Output is correct |
8 |
Correct |
195 ms |
3660 KB |
Output is correct |
9 |
Correct |
176 ms |
1612 KB |
Output is correct |
10 |
Correct |
180 ms |
1700 KB |
Output is correct |
11 |
Correct |
272 ms |
69484 KB |
Output is correct |
12 |
Correct |
278 ms |
69460 KB |
Output is correct |
13 |
Correct |
214 ms |
13744 KB |
Output is correct |
14 |
Correct |
221 ms |
13824 KB |
Output is correct |
15 |
Correct |
204 ms |
53160 KB |
Output is correct |
16 |
Correct |
204 ms |
53180 KB |
Output is correct |
17 |
Correct |
245 ms |
62540 KB |
Output is correct |
18 |
Correct |
248 ms |
62592 KB |
Output is correct |
19 |
Correct |
260 ms |
66136 KB |
Output is correct |
20 |
Correct |
259 ms |
66252 KB |
Output is correct |