# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
697133 |
2023-02-08T14:21:27 Z |
dsyz |
Growing Trees (BOI11_grow) |
C++17 |
|
196 ms |
18720 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MAXN (1000005)
struct node{
ll s, e, m, val, maxi, lazy;
node *l, *r;
node(ll S, ll E){
s = S, e = E, m = (s+e)/2;
val = 0;
maxi = 0;
lazy = 0;
if(s != e){
l = new node(s,m);
r = new node(m + 1,e);
}
}
void propogate(){
if(lazy==0) return;
val += lazy*(e-s+1);
maxi += lazy;
if(s != e){ //not a leaf, send lazy tags to children (remember to write this if statement)
l->lazy += lazy;
r->lazy += lazy;
}
lazy = 0;
}
void update(int S, int E, ll V){
if(s == S && e == E) lazy += V;
else{
if(E <= m) l->update(S, E, V);
else if (m < S) r->update(S, E, V);
else l->update(S, m, V),r->update(m+1, E, V);
l->propogate(),r->propogate();
val = l->val + r->val;
maxi = max(l -> maxi,r -> maxi);
}
}
ll bsL(ll H){ //leftmost position >= H
propogate(); //remember to propogate
if(s == e){
if(maxi >= H) return s;
else return 1000000005;
}
l -> propogate(), r -> propogate();
if(l -> maxi >= H){
return l -> bsL(H);
}else if(r -> maxi >= H){
return r -> bsL(H);
}else{
return 1000000005;
}
}
ll query(int S, int E){
propogate(); //remember to propogate
if(s == S && e == E) return val;
else if(E <= m) return l->query(S, E);
else if(S >= m+1) return r->query(S, E);
else return l->query(S, m) + r->query(m+1, E);
}
} *root;
int main(){
ios_base::sync_with_stdio(false);cin.tie(0);
ll N,M;
cin>>N>>M;
root = new node(0,N - 1);
ll arr[N];
for(ll i = 0;i < N;i++){
cin>>arr[i];
}
sort(arr,arr + N);
for(ll i = 0;i < N;i++){
root -> update(i,i,arr[i]);
}
for(ll i = 0;i < M;i++){
char t;
cin>>t;
if(t == 'F'){
ll c,h;
cin>>c>>h;
ll start = root -> bsL(h);
if(start == 1000000005){
continue;
}
ll endval = root -> query(min(N - 1,start + c - 1),min(N - 1,start + c - 1));
ll end = -1e18;
end = root -> bsL(endval);
end--;
ll end2 = root -> bsL(endval + 1);
if(end2 == 1000000005){
end2 = N - 1;
}else{
end2--;
}
ll start2 = max(end + 1,end2 - (c - (end - start + 1)) + 1);
if(start2 == 1000000005){
continue;
}
if(start <= end) root -> update(start,end,1);
if(start2 <= end2) root -> update(start2,end2,1);
}else if(t == 'C'){
ll L,R;
cin>>L>>R;
ll start = root -> bsL(L);
ll end = root -> bsL(R + 1);
if(end == 1000000005){
end = N - 1;
}else{
end--;
}
if(start == 1000000005 || end == 1000000005){
cout<<0<<'\n';
}else{
cout<<end - start + 1<<'\n';
}
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
100 ms |
16076 KB |
Output is correct |
2 |
Correct |
168 ms |
16084 KB |
Output is correct |
3 |
Correct |
110 ms |
15424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
588 KB |
Output is correct |
2 |
Correct |
2 ms |
596 KB |
Output is correct |
3 |
Correct |
3 ms |
596 KB |
Output is correct |
4 |
Correct |
2 ms |
596 KB |
Output is correct |
5 |
Correct |
41 ms |
2100 KB |
Output is correct |
6 |
Correct |
50 ms |
2368 KB |
Output is correct |
7 |
Correct |
6 ms |
1108 KB |
Output is correct |
8 |
Correct |
22 ms |
1868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
2712 KB |
Output is correct |
2 |
Correct |
59 ms |
2872 KB |
Output is correct |
3 |
Correct |
3 ms |
1352 KB |
Output is correct |
4 |
Correct |
29 ms |
2300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
2880 KB |
Output is correct |
2 |
Correct |
58 ms |
2708 KB |
Output is correct |
3 |
Correct |
10 ms |
1568 KB |
Output is correct |
4 |
Correct |
53 ms |
2856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
87 ms |
12040 KB |
Output is correct |
2 |
Correct |
144 ms |
13516 KB |
Output is correct |
3 |
Correct |
17 ms |
3540 KB |
Output is correct |
4 |
Correct |
91 ms |
13424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
131 ms |
13644 KB |
Output is correct |
2 |
Correct |
144 ms |
14580 KB |
Output is correct |
3 |
Correct |
108 ms |
13472 KB |
Output is correct |
4 |
Correct |
18 ms |
3540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
14620 KB |
Output is correct |
2 |
Correct |
115 ms |
16140 KB |
Output is correct |
3 |
Correct |
113 ms |
15076 KB |
Output is correct |
4 |
Correct |
17 ms |
3528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
167 ms |
16108 KB |
Output is correct |
2 |
Correct |
149 ms |
14156 KB |
Output is correct |
3 |
Correct |
52 ms |
17444 KB |
Output is correct |
4 |
Correct |
69 ms |
16224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
120 ms |
15796 KB |
Output is correct |
2 |
Correct |
142 ms |
16296 KB |
Output is correct |
3 |
Correct |
196 ms |
18344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
142 ms |
18720 KB |
Output is correct |