# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
520471 |
2022-01-30T06:38:53 Z |
blue |
Growing Trees (BOI11_grow) |
C++17 |
|
40 ms |
5892 KB |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using vi = vector<int>;
using ll = long long;
using vll = vector<ll>;
const int mx = 100'000;
const int Z = (1<<17);
vll delta(1+mx);
int N, M;
struct segtree
{
vi l = vi(1+Z);
vi r = vi(1+Z);
vll sm = vll(1+Z);
segtree()
{
;
}
void build(int i, int L, int R)
{
l[i] = L;
r[i] = R;
if(l[i] == r[i])
{
sm[i] = delta[l[i]];
}
else
{
build(2*i, L, (L+R)/2);
build(2*i+1, (L+R)/2+1, R);
sm[i] = sm[2*i] + sm[2*i+1];
}
}
int first_geq(int i, ll s)
{
// cerr << i << ' ' << l[i] << ' ' << r[i] << " : " << sm[i] << ' ' << s << '\n';
if(sm[i] < s) return N+1;
else if(l[i] == r[i]) return l[i];
else if(sm[i<<1] >= s) return first_geq(i<<1, s);
else return first_geq((i<<1) + 1, s - sm[i<<1]);
}
int first_geq(ll s) {return first_geq(1, s);}
void add(int i, int I, ll V)
{
sm[i] += V;
if(l[i] != r[i])
{
if(I <= (l[i] + r[i])/2) add(2*i, I, V);
else add(2*i+1, I, V);
}
}
void add(int I, int V) {add(1, I, V);}
int get_sum(int i, int I)
{
if(l[i] == r[i]) return sm[i];
else if(I <= (l[i] + r[i])/2) return get_sum(i<<1, I);
else return sm[(i<<1)] + get_sum((i<<1) + 1, I);
}
};
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> N >> M;
vll init_h(1+N);
for(int i = 1; i <= N; i++) cin >> init_h[i];
init_h[0] = 0;
sort(init_h.begin(), init_h.end());
for(int i = 1; i <= N; i++) delta[i] = init_h[i] - init_h[i-1];
segtree S;
S.build(1, 1, N);
for(int q = 1; q <= M; q++)
{
char t;
cin >> t;
if(t == 'F')
{
ll c, h;
cin >> c >> h;
int stp = S.first_geq(h);
if(stp >= N+1) continue;
int ep = min(stp + c - 1, (ll)N);
ll ep_val = S.get_sum(1, ep);
int last_start = S.first_geq(1, ep_val);
int last_end = S.first_geq(1, ep_val+1) - 1;
int last_count = ep - last_start + 1;
S.add(last_end - last_count + 1, +1);
S.add(last_end+1, -1);
S.add(stp, +1);
S.add(last_start, -1);
}
else
{
ll mn, mx;
cin >> mn >> mx;
cout << S.first_geq(1, mx+1) - S.first_geq(1, mn) << '\n';
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
26 ms |
5036 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3176 KB |
Output is correct |
2 |
Incorrect |
3 ms |
3144 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
25 ms |
4328 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
23 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
31 ms |
4828 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
24 ms |
4756 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
23 ms |
4796 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
39 ms |
5524 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
40 ms |
5360 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
37 ms |
5892 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |