/*
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
*/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int>vi;
typedef vector<vector<int>>vvi;
typedef vector<ll>vl;
typedef vector<vl> vvl;
typedef pair<int,int>pi;
typedef pair<ll,ll> pl;
typedef vector<pl> vpl;
typedef vector<ld> vld;
typedef pair<ld,ld> pld;
typedef vector<pi> vpi;
//typedef tree<ll, null_type, less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
template<typename T> ostream& operator<<(ostream& os, vector<T>& a){os<<"[";for(int i=0; i<ll(a.size()); i++){os << a[i] << ((i!=ll(a.size()-1)?" ":""));}os << "]\n"; return os;}
#define all(x) x.begin(),x.end()
#define YES out("YES")
#define NO out("NO")
#define out(x){cout << x << "\n"; return;}
#define outfl(x){cout << x << endl;return;}
#define GLHF ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define print(x){for(auto ait:x) cout << ait << " "; cout << "\n";}
#define pb push_back
#define umap unordered_map
template<typename T>
void read(vector<T>& v){
int n=v.size();
for(int i=0; i<n; i++)
cin >> v[i];
}
template<typename T>
vector<T>UNQ(vector<T>a){
vector<T>ans;
for(T t:a)
if(ans.empty() || t!=ans.back())
ans.push_back(t);
return ans;
}
void solve();
int main(){
GLHF;
int t=1;
//cin >> t;
while(t--)
solve();
}
struct seg{
vl t;
int sz=1,n;
seg(int _n):n(_n){
sz=2*n;
t.resize(sz);
}
void add(int l,int r,ll v){
for(l+=sz/2,r+=sz/2 +1; l<r; l/=2,r/=2){
if(l&1)t[l++]+=v;
if(r&1)t[--r]+=v;
}
}
ll qur(ll i){
i+=sz/2;
ll ans=0;
while(i){
ans+=t[i];
i/=2;
}
return ans;
}
ll first_greater_equal(ll k){
ll l=0,r=n-1,ans=n;
while(l<=r){
int m=(l+r)/2;
if(qur(m)>=k)
ans=m,r=m-1;
else
l=m+1;
}
return ans;
}
};
void solve() {
//freopen("C:\\Users\\User\\Downloads\\boi2011_tests\\grow\\grow.g04A.in","r",stdin);
ll n,q;
cin >> n >> q;
vl a(n);
read(a);
sort(all(a));
seg ST(n);
for(int i=0; i<n; i++)
ST.add(i,i,a[i]);
while(q--){
char op;
cin >> op;
if(op=='C'){
int l,r;
cin >> l >> r;
int first = ST.first_greater_equal(l);
int last = ST.first_greater_equal(r+1);
cout << last-first << endl;
continue;
}
ll c,h;
cin >> c >> h;
int first = ST.first_greater_equal(h);
if(first==n)
continue;
c=min(c,n-first);
int last = min(first+c-1,n-1);
int height_last = ST.qur(last);
last = ST.first_greater_equal(height_last)-1;
ll p_last = last;
ST.add(first,last,1);
if(last==n-1)
continue;
c-= last-first+1;
last = ST.first_greater_equal(height_last+1)-1;
first = max(p_last+1,last-c+1);
ST.add(first,last,1);
}
}
/*
3 2
1 2 3
F 3 2
C 4 4
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
135 ms |
2508 KB |
Output is correct |
2 |
Correct |
180 ms |
3988 KB |
Output is correct |
3 |
Correct |
106 ms |
3916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
2 |
Correct |
7 ms |
340 KB |
Output is correct |
3 |
Correct |
7 ms |
360 KB |
Output is correct |
4 |
Correct |
4 ms |
340 KB |
Output is correct |
5 |
Correct |
131 ms |
568 KB |
Output is correct |
6 |
Correct |
176 ms |
752 KB |
Output is correct |
7 |
Correct |
8 ms |
468 KB |
Output is correct |
8 |
Correct |
135 ms |
1248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
168 ms |
772 KB |
Output is correct |
2 |
Correct |
156 ms |
1876 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
142 ms |
1332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
170 ms |
816 KB |
Output is correct |
2 |
Correct |
177 ms |
1732 KB |
Output is correct |
3 |
Correct |
8 ms |
596 KB |
Output is correct |
4 |
Correct |
157 ms |
1856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
141 ms |
2008 KB |
Output is correct |
2 |
Correct |
170 ms |
3324 KB |
Output is correct |
3 |
Correct |
39 ms |
1084 KB |
Output is correct |
4 |
Correct |
89 ms |
3392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
139 ms |
2100 KB |
Output is correct |
2 |
Correct |
175 ms |
3572 KB |
Output is correct |
3 |
Correct |
111 ms |
3612 KB |
Output is correct |
4 |
Correct |
40 ms |
1092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
142 ms |
2352 KB |
Output is correct |
2 |
Correct |
153 ms |
3644 KB |
Output is correct |
3 |
Correct |
108 ms |
3844 KB |
Output is correct |
4 |
Correct |
39 ms |
1120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
178 ms |
2380 KB |
Output is correct |
2 |
Correct |
180 ms |
2304 KB |
Output is correct |
3 |
Correct |
33 ms |
3276 KB |
Output is correct |
4 |
Correct |
148 ms |
3572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
176 ms |
2496 KB |
Output is correct |
2 |
Correct |
186 ms |
4004 KB |
Output is correct |
3 |
Correct |
157 ms |
4424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
218 ms |
3112 KB |
Output is correct |