#include "ricehub.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
struct st{
vector<ll> cad;
void update(ll a, ll b)
{
for(a; a<cad.size(); a+=(a&-a)) cad[a]+=b;
}
ll query(ll a)
{
ll s=0;
for(a; a>0; a-=(a&-a)) s+=cad[a];
return s;
}
ll query(ll a, ll b) {return query(b)-query(a-1);}
st(ll n){ cad.resize(n+5);}
}asd(300000);
int besthub(int R, int L, int X[], long long B)
{
ll n=R,k=B,c=1;
ordered_set s;
ll cad[n];
vector<ll>asdf;
map<ll,ll> mapa;
for(int i=0; i<n; i++)
{
cad[i]=X[i];
asdf.push_back(cad[i]);
}
sort(asdf.begin(),asdf.end());
for(auto i:asdf){if(mapa[i]==0){mapa[i]=c++;}}
ll z=0;
ll bs=0;
for(int i=0; i<n; i++)
{
s.insert(cad[i]);
asd.update(mapa[cad[i]],cad[i]);
ll mediana = *s.find_by_order((s.size()-1)/2);
ll temp=s.order_of_key(mediana);
while(temp*mediana-asd.query(mapa[mediana]-1)+asd.query(mapa[mediana],300000)-(s.size()-temp)*mediana>k)
{
s.erase(s.find_by_order(s.order_of_key(cad[z])));
asd.update(mapa[cad[z]],-cad[z]);
z++;
mediana = *s.find_by_order((s.size()-1)/2);
temp=s.order_of_key(mediana);
}
//cerr<<temp*mediana-asd.query(mapa[mediana]-1)+asd.query(mapa[mediana],300000)-(s.size()-temp)*mediana<<" ";
//cerr<<z<<" "<<i<<"\n";
bs=max(bs,(ll)s.size());
}
return (int)bs;
}
Compilation message
ricehub.cpp: In member function 'void st::update(ll, ll)':
ricehub.cpp:15:13: warning: statement has no effect [-Wunused-value]
15 | for(a; a<cad.size(); a+=(a&-a)) cad[a]+=b;
| ^
ricehub.cpp:15:17: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
15 | for(a; a<cad.size(); a+=(a&-a)) cad[a]+=b;
| ~^~~~~~~~~~~
ricehub.cpp: In member function 'll st::query(ll)':
ricehub.cpp:20:13: warning: statement has no effect [-Wunused-value]
20 | for(a; a>0; a-=(a&-a)) s+=cad[a];
| ^
ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:50:110: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'll' {aka 'long long int'} [-Wsign-compare]
50 | while(temp*mediana-asd.query(mapa[mediana]-1)+asd.query(mapa[mediana],300000)-(s.size()-temp)*mediana>k)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2640 KB |
Output is correct |
2 |
Correct |
1 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2640 KB |
Output is correct |
4 |
Correct |
1 ms |
2640 KB |
Output is correct |
5 |
Correct |
2 ms |
2640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2640 KB |
Output is correct |
2 |
Correct |
1 ms |
2640 KB |
Output is correct |
3 |
Correct |
1 ms |
2640 KB |
Output is correct |
4 |
Correct |
1 ms |
2640 KB |
Output is correct |
5 |
Correct |
1 ms |
2796 KB |
Output is correct |
6 |
Correct |
2 ms |
2808 KB |
Output is correct |
7 |
Correct |
1 ms |
2640 KB |
Output is correct |
8 |
Correct |
1 ms |
2640 KB |
Output is correct |
9 |
Correct |
2 ms |
2640 KB |
Output is correct |
10 |
Correct |
1 ms |
2640 KB |
Output is correct |
11 |
Correct |
2 ms |
2800 KB |
Output is correct |
12 |
Correct |
1 ms |
2640 KB |
Output is correct |
13 |
Correct |
2 ms |
2640 KB |
Output is correct |
14 |
Correct |
2 ms |
2868 KB |
Output is correct |
15 |
Correct |
2 ms |
2640 KB |
Output is correct |
16 |
Correct |
1 ms |
2640 KB |
Output is correct |
17 |
Correct |
1 ms |
2640 KB |
Output is correct |
18 |
Correct |
1 ms |
2652 KB |
Output is correct |
19 |
Correct |
1 ms |
2640 KB |
Output is correct |
20 |
Correct |
1 ms |
2896 KB |
Output is correct |
21 |
Correct |
2 ms |
2640 KB |
Output is correct |
22 |
Correct |
2 ms |
2640 KB |
Output is correct |
23 |
Correct |
2 ms |
2640 KB |
Output is correct |
24 |
Correct |
2 ms |
2640 KB |
Output is correct |
25 |
Correct |
2 ms |
2640 KB |
Output is correct |
26 |
Correct |
2 ms |
2640 KB |
Output is correct |
27 |
Correct |
2 ms |
2640 KB |
Output is correct |
28 |
Correct |
2 ms |
2640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2816 KB |
Output is correct |
2 |
Correct |
1 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2896 KB |
Output is correct |
4 |
Correct |
2 ms |
2896 KB |
Output is correct |
5 |
Correct |
2 ms |
2640 KB |
Output is correct |
6 |
Correct |
1 ms |
2640 KB |
Output is correct |
7 |
Correct |
2 ms |
2640 KB |
Output is correct |
8 |
Correct |
2 ms |
2640 KB |
Output is correct |
9 |
Correct |
1 ms |
2640 KB |
Output is correct |
10 |
Correct |
2 ms |
2812 KB |
Output is correct |
11 |
Correct |
2 ms |
2640 KB |
Output is correct |
12 |
Correct |
2 ms |
2640 KB |
Output is correct |
13 |
Correct |
2 ms |
2896 KB |
Output is correct |
14 |
Correct |
2 ms |
3072 KB |
Output is correct |
15 |
Correct |
1 ms |
2640 KB |
Output is correct |
16 |
Correct |
1 ms |
2640 KB |
Output is correct |
17 |
Correct |
1 ms |
2896 KB |
Output is correct |
18 |
Correct |
2 ms |
2808 KB |
Output is correct |
19 |
Correct |
2 ms |
2896 KB |
Output is correct |
20 |
Correct |
2 ms |
2896 KB |
Output is correct |
21 |
Correct |
3 ms |
2896 KB |
Output is correct |
22 |
Correct |
3 ms |
2896 KB |
Output is correct |
23 |
Correct |
4 ms |
3408 KB |
Output is correct |
24 |
Correct |
4 ms |
3408 KB |
Output is correct |
25 |
Correct |
5 ms |
3408 KB |
Output is correct |
26 |
Correct |
5 ms |
3420 KB |
Output is correct |
27 |
Correct |
5 ms |
3396 KB |
Output is correct |
28 |
Correct |
5 ms |
3420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
4300 KB |
Output is correct |
2 |
Correct |
19 ms |
4556 KB |
Output is correct |
3 |
Correct |
139 ms |
19940 KB |
Output is correct |
4 |
Correct |
137 ms |
20088 KB |
Output is correct |
5 |
Correct |
22 ms |
6348 KB |
Output is correct |
6 |
Correct |
22 ms |
6516 KB |
Output is correct |
7 |
Correct |
106 ms |
13744 KB |
Output is correct |
8 |
Correct |
101 ms |
13768 KB |
Output is correct |
9 |
Correct |
56 ms |
6856 KB |
Output is correct |
10 |
Correct |
46 ms |
6856 KB |
Output is correct |
11 |
Correct |
154 ms |
20016 KB |
Output is correct |
12 |
Correct |
157 ms |
20132 KB |
Output is correct |
13 |
Correct |
62 ms |
9040 KB |
Output is correct |
14 |
Correct |
59 ms |
9164 KB |
Output is correct |
15 |
Correct |
101 ms |
16160 KB |
Output is correct |
16 |
Correct |
102 ms |
16060 KB |
Output is correct |
17 |
Correct |
128 ms |
18372 KB |
Output is correct |
18 |
Correct |
122 ms |
18364 KB |
Output is correct |
19 |
Correct |
140 ms |
19164 KB |
Output is correct |
20 |
Correct |
142 ms |
19132 KB |
Output is correct |