/*
*/
#include "ricehub.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
template <class T> using ot = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define ins insert
#define pb push_back
// #define long long long long long long
#define pii pair<long long, long long>
#define endl '\n'
#define drop(x) cout<<(x)<<endl; return;
#define all(x) x.begin(),x.end()
const long long sze=1e5 +10;
pair<long long,long long> T[sze+10];
const long long inf = INT_MAX;
void upd(long long node,long long v,long long y){
node++;
while(node<=sze){
T[node].first+=v;
T[node].second+=y;
node += (node & -node);
}
}
pair<long long,long long> qry(long long node){
node++;
pair<long long,long long> res;
while(node>0){
res.first+=T[node].first;
res.second += T[node].second;
node -= (node & -node);
}
return res;
}
int besthub(int n, int mxL, int arr[], long long B){
long long ans=1;
/*
her i ucun ele j tapaqki :
j<i
j ni goturmesek i+1 right terefden nese ekstra goture bilirik
*/
long long l =1;
long long r = n;
vector<long long> pref(n+1,0);
for(long long i=0;i<n;i++){
pref[i]+=arr[i];
if(i){
pref[i]+=pref[i-1];
}
}
auto calc = [&](long long lx,long long rx,long long orta){
return arr[orta]*(orta-lx) - (orta?pref[orta-1] - (lx?pref[lx - 1]:0):0) +
pref[rx] - pref[orta] - arr[orta]*(rx-orta);
};
while(l<=r){
long long mid = (l+r)/2;
bool check=false;
long long x = mid%2 ;
for(long long i =0;i<=n-mid;i++){
long long c =0;
long long lx = i;
long long rx = i+mid-1;
long long orta = (lx+rx)/2;
c = calc(lx,rx,orta);
if(c<=B){
check=true;
break;
}
}
if(check){
ans=max(ans,mid);
l=mid+1;
}
else{
r=mid-1;
}
}
return ans;
}
Compilation message
ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:69:19: warning: unused variable 'x' [-Wunused-variable]
69 | long long x = mid%2 ;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 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 |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 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 |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 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 |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 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 |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 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 |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
600 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
3 |
Correct |
11 ms |
1572 KB |
Output is correct |
4 |
Correct |
12 ms |
1628 KB |
Output is correct |
5 |
Correct |
4 ms |
860 KB |
Output is correct |
6 |
Correct |
4 ms |
856 KB |
Output is correct |
7 |
Correct |
7 ms |
1372 KB |
Output is correct |
8 |
Correct |
7 ms |
1624 KB |
Output is correct |
9 |
Correct |
4 ms |
856 KB |
Output is correct |
10 |
Correct |
6 ms |
976 KB |
Output is correct |
11 |
Correct |
9 ms |
1624 KB |
Output is correct |
12 |
Correct |
8 ms |
1544 KB |
Output is correct |
13 |
Correct |
9 ms |
860 KB |
Output is correct |
14 |
Correct |
5 ms |
860 KB |
Output is correct |
15 |
Correct |
6 ms |
1232 KB |
Output is correct |
16 |
Correct |
6 ms |
1116 KB |
Output is correct |
17 |
Correct |
7 ms |
1500 KB |
Output is correct |
18 |
Correct |
7 ms |
1492 KB |
Output is correct |
19 |
Correct |
8 ms |
1516 KB |
Output is correct |
20 |
Correct |
12 ms |
1372 KB |
Output is correct |