#include <bits/extc++.h>
#include <ext/pb_ds/tag_and_trait.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
#define ALL(i) i.begin(),i.end()
#define SZ(i) int(i.size())
#define X first
#define Y second
#define eb emplace_back
#define pb push_back
#ifdef tmd
#define debug(...) fprintf(stderr,"#%d-(%s)=",__LINE__,#__VA_ARGS__);_do(__VA_ARGS__);
template<typename T> void _do(T &&x) {cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y) {cerr<<x<<",";_do(y...);}
template<typename IT> ostream& printRng (ostream& os, IT bg, IT ed) {
os << "{";
for (IT it=bg; it!=ed; it++) {
if (it == bg) os << *it;
else os << "," << *it;
}
return os << "}";
}
template<typename T> ostream& operator << (ostream& os, const vector<T>& v) {return printRng(os,ALL(v));}
#else
#define debug(...)
#endif
#include "ricehub.h"
ll n;
ll b;
vector<ll> pos;
struct Bit {
ll N;
vector<ll> bit;
Bit (ll sz) : N(sz+3), bit(sz+3) {}
void add (ll x, ll val) {
for (x++; x<N; x+=-x&x) {
bit[x] += val;
}
}
ll qry (ll x) {
ll res = 0;
for (x++; x; x-=-x&x) {
res += bit[x];
}
return res;
}
};
bool check (ll len) {
Bit sum(n);
for (ll i=0; i<n; i++) {
sum.add(i, pos[i]);
if (i >= len - 1) {
ll pmid = i - len/2;
ll L = 1LL*pos[pmid]*(len-len/2) - sum.qry(pmid);
ll R = sum.qry(n) - sum.qry(pmid) - 1LL*pos[pmid]*(len/2);
if (L + R <= b) {
return true;
}
sum.add(i-len+1, -pos[i-len+1]);
}
}
return false;
}
int besthub(int R, int L, int X[], long long B) {
n = R;
b = B;
for (ll i=0; i<R; i++) {
pos.eb(X[i]);
}
ll l = 1, r = R + 1;
while (l < r - 1) {
ll m = (l + r) >> 1;
if (check(m)) {
l = m;
} else {
r = m;
}
}
return l;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
256 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
256 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
256 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
512 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
380 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
288 KB |
Output is correct |
21 |
Correct |
3 ms |
512 KB |
Output is correct |
22 |
Correct |
4 ms |
512 KB |
Output is correct |
23 |
Correct |
2 ms |
512 KB |
Output is correct |
24 |
Correct |
2 ms |
640 KB |
Output is correct |
25 |
Correct |
2 ms |
512 KB |
Output is correct |
26 |
Correct |
3 ms |
512 KB |
Output is correct |
27 |
Correct |
4 ms |
512 KB |
Output is correct |
28 |
Correct |
4 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
892 KB |
Output is correct |
2 |
Correct |
17 ms |
892 KB |
Output is correct |
3 |
Correct |
62 ms |
2420 KB |
Output is correct |
4 |
Correct |
45 ms |
2420 KB |
Output is correct |
5 |
Correct |
41 ms |
1400 KB |
Output is correct |
6 |
Correct |
45 ms |
1400 KB |
Output is correct |
7 |
Correct |
44 ms |
2416 KB |
Output is correct |
8 |
Correct |
41 ms |
2420 KB |
Output is correct |
9 |
Correct |
38 ms |
1400 KB |
Output is correct |
10 |
Correct |
38 ms |
1400 KB |
Output is correct |
11 |
Correct |
51 ms |
2412 KB |
Output is correct |
12 |
Correct |
47 ms |
2420 KB |
Output is correct |
13 |
Correct |
42 ms |
1400 KB |
Output is correct |
14 |
Correct |
53 ms |
1400 KB |
Output is correct |
15 |
Correct |
34 ms |
1908 KB |
Output is correct |
16 |
Correct |
34 ms |
1908 KB |
Output is correct |
17 |
Correct |
46 ms |
2196 KB |
Output is correct |
18 |
Correct |
53 ms |
2164 KB |
Output is correct |
19 |
Correct |
42 ms |
2284 KB |
Output is correct |
20 |
Correct |
47 ms |
2292 KB |
Output is correct |