#include <bits/stdc++.h>
#define MAXN 100010
using namespace std;
int height[MAXN];
class SegmentTree{
private:
int n;
vector<int> st, marked;
int left(int p){ return 2*p; }
int right(int p){ return 2*p+1; }
void build(int p, int L, int R){
if( L == R ){ st[p] = height[L]; return; }
int mid = (L+R)/2;
build(left(p), L, mid); build(right(p), mid+1, R);
st[p] = max(st[left(p)], st[right(p)]); //make sure this is right
}
void push(int p, int L, int R){
if( L == R ) return;
int k = marked[p];
marked[left(p)] += k; marked[right(p)] += k; marked[p] = 0;
st[left(p)] += k; st[right(p)] += k;
}
void update(int p, int L, int R, int i, int j){
if( i > R || j < L ) return;
if( L >= i && R <= j ){
marked[p] += 1;
st[p] += 1;
return;
}
int mid = (L+R)/2;
if( marked[p] ) push(p, L, R);
update(left(p), L, mid, i, j); update(right(p), mid+1, R, i, j);
st[p] = max(st[left(p)], st[right(p)]);
}
int query(int p, int L, int R, int h){
if( st[p] < h ) return 0;
if( L == R ) return L;
int mid = (L+R)/2;
if( marked[p] ) push(p, L, R);
if( st[left(p)] >= h ) return query(left(p), L, mid, h);
return query(right(p), mid+1, R, h);
}
public:
SegmentTree(int _n) : n(_n){
marked.assign(4*n, 0);
st.resize(4*n);
build(1, 1, n);
}
void update(int i, int j){ update(1, 1, n, i, j); }
int query(int h){ return query(1, 1, n, h); }
};
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int trees, queries;
cin>>trees>>queries;
for( int i{1} ; i <= trees ; ++i ) cin>>height[i];
sort(height+1, height+1+trees);
height[trees+1] = INT_MAX;
SegmentTree st(trees+1);
while( queries-- ){
char type; cin>>type;
if( type == 'F' ){
int c, h;
cin>>c>>h;
int p1 = st.query(h);
int p2 = min(trees, p1+c-1);
if( height[p2] < height[p2+1] ) st.update(p1, p2);
else{
int p3 = st.query(height[p2])-1;
int l = p3 - p1 + 1; c -= l;
st.update(p1, p3);
int p4 = st.query(height[p2]+1);
p3 = p4-c;
st.update(p3, p4-1);
}
}
else{
int l, r;
cin>>l>>r;
int p1 = st.query(l);
int p2 = st.query(r+1);
cout<<p2-p1<<'\n';
}
//any edge cases you are missing?
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
37 ms |
4580 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
38 ms |
1752 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
33 ms |
1740 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
38 ms |
3640 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
42 ms |
4016 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
37 ms |
4204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
90 ms |
5064 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
67 ms |
4604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
74 ms |
6044 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |