#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#define ll long long
#define endl "\n"
#define inf LLONG_MAX
#define vll vector<ll>
#define sd second
#define ft first
#define al(x) x.begin(),x.end()
#define alr(x) x.rbegin(),x.rend()
#define pll pair<ll, ll>
#define mod 1000000007
#define _set tree<pll, null_type, less<pll>, rb_tree_tag, tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;
vector<ll> v1;
vector<pair<ll, ll>> t;
inline void build(ll v, ll tl, ll tr){
if(tl==tr){
t[v]={v1[tl], -v1[tl]};
}else{
ll tm=(tl+tr)/2;
build(v*2, tl, tm);
build(v*2+1, tm+1, tr);
t[v].ft=t[v*2].ft+t[v*2+1].ft;
t[v].sd=t[v*2].sd+t[v*2+1].sd;
}
}
inline ll query(ll v, ll tl, ll tr, ll l, ll r){
if(tl>r || tr<l)return 0;
if(tl>=l && tr<=r)return t[v].ft;
ll tm=(tl+tr)/2;
return query(v*2, tl, tm, l, r)+query(v*2+1, tm+1, tr, l, r);
}
inline ll query1(ll v, ll tl, ll tr, ll l, ll r){
if(tl>r || tr<l)return 0;
if(tl>=l && tr<=r)return t[v].sd;
ll tm=(tl+tr)/2;
return query1(v*2, tl, tm, l, r)+query1(v*2+1, tm+1, tr, l, r);
}
int besthub(int R, int L, int X[], long long B){
ll a, b, c, d, e, f;
a=R;
b=L;
c=B;
t.clear();
v1.clear();
t.resize(4*a);
v1.resize(a);
for(int i=0; i<a; i++)v1[i]=X[i];
build(1, 0, a-1);
ll res=0;
for(int i=0; i<a; i++){
ll tl=i, tr=a-1;
while(tl<=tr){
ll tm2=(tl+tr)/2, tm=(i+tm2)/2, tm1=tm+1;
ll// o=query1(1, 0, a-1, i, tm)+(v1[tm]*((tm-i)+1)), o1=query(1, 0, a-1, tm, tm2)-(v1[tm]*((tm2-tm)+1));
o2=query1(1, 0, a-1, i, tm1)+(v1[tm1]*((tm1-i)+1)), o3=query(1, 0, a-1, tm1, tm2)-(v1[tm1]*((tm2-tm1)+1));
//cout<<i<<" "<<tl<<" "<<tr<<endl;
//if(i==2)cout<<o<<" "<<o1<<" "<<tm2<<" "<<tm1<<" "<<tm<<endl;
//if(o+o1<=c)res=max(res, (tm2-i)+1);
if(o2+o3<=c)res=max(res, (tm2-i)+1);
if(o2+o3<=c)tl=tm2+1;
else tr=tm2-1;
}
}
return res;
}
Compilation message
ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:42:11: warning: variable 'b' set but not used [-Wunused-but-set-variable]
42 | ll a, b, c, d, e, f;
| ^
ricehub.cpp:42:17: warning: unused variable 'd' [-Wunused-variable]
42 | ll a, b, c, d, e, f;
| ^
ricehub.cpp:42:20: warning: unused variable 'e' [-Wunused-variable]
42 | ll a, b, c, d, e, f;
| ^
ricehub.cpp:42:23: warning: unused variable 'f' [-Wunused-variable]
42 | ll a, b, c, d, e, f;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
448 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
356 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
444 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
452 KB |
Output is correct |
28 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
344 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
448 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
348 KB |
Output is correct |
14 |
Correct |
2 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
3 ms |
348 KB |
Output is correct |
20 |
Correct |
2 ms |
344 KB |
Output is correct |
21 |
Correct |
10 ms |
604 KB |
Output is correct |
22 |
Correct |
10 ms |
856 KB |
Output is correct |
23 |
Correct |
11 ms |
856 KB |
Output is correct |
24 |
Correct |
9 ms |
860 KB |
Output is correct |
25 |
Correct |
9 ms |
868 KB |
Output is correct |
26 |
Correct |
9 ms |
860 KB |
Output is correct |
27 |
Correct |
10 ms |
872 KB |
Output is correct |
28 |
Correct |
10 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
1884 KB |
Output is correct |
2 |
Correct |
47 ms |
1880 KB |
Output is correct |
3 |
Correct |
324 ms |
8796 KB |
Output is correct |
4 |
Correct |
317 ms |
8792 KB |
Output is correct |
5 |
Correct |
133 ms |
4504 KB |
Output is correct |
6 |
Correct |
144 ms |
4444 KB |
Output is correct |
7 |
Correct |
322 ms |
8652 KB |
Output is correct |
8 |
Correct |
318 ms |
8540 KB |
Output is correct |
9 |
Correct |
144 ms |
4444 KB |
Output is correct |
10 |
Correct |
143 ms |
4440 KB |
Output is correct |
11 |
Correct |
312 ms |
8796 KB |
Output is correct |
12 |
Correct |
305 ms |
8792 KB |
Output is correct |
13 |
Correct |
137 ms |
4444 KB |
Output is correct |
14 |
Correct |
138 ms |
4556 KB |
Output is correct |
15 |
Correct |
218 ms |
6708 KB |
Output is correct |
16 |
Correct |
217 ms |
6744 KB |
Output is correct |
17 |
Correct |
274 ms |
8024 KB |
Output is correct |
18 |
Correct |
272 ms |
7972 KB |
Output is correct |
19 |
Correct |
302 ms |
8280 KB |
Output is correct |
20 |
Correct |
300 ms |
8280 KB |
Output is correct |