#include<bits/stdc++.h>
#define el '\n'
#define fi first
#define sc second
#define int ll
#define pii pair<int, int>
#define all(v) v.begin(), v.end()
using namespace std;
using ll=long long;
using ull=unsigned long long;
using ld=long double;
const int mod=1e9+7;
const int N=1e5+11;
struct node
{
int sum, lazy;
node* l;
node* r;
node()
{
sum=0, lazy=0;
l=r=NULL;
}
};
node* root;
int n, a[N], q;
void down(node* pos, int l, int r)
{
if(pos->lazy==0) return;
int mid=(l+r)>>1;
pos->l->lazy+=pos->lazy;
pos->r->lazy+=pos->lazy;
pos->l->sum+=(pos->lazy)*(mid-l+1);
pos->r->sum+=(pos->lazy)*(r-mid);
}
void update(node* pos, int l, int r, int u, int v, int val)
{
if(r<u || v<l) return;
if(u<=l && r<=v)
{
pos->sum+=val*(r-l+1);
pos->lazy+=val;
return;
}
if(pos->l==NULL) pos->l = new node();
if(pos->r==NULL) pos->r = new node();
int mid=(l+r)/2;
down(pos, l, r);
update(pos->l, l, mid, u, v, val);
update(pos->r, mid+1, r, u, v, val);
pos->sum=pos->l->sum+pos->r->sum;
}
int get(node* pos, int l, int r, int u, int v)
{
if(r<u || v<l) return 0;
if(u<=l && r<=v)
{
return pos->sum;
}
if(pos->l==NULL) pos->l = new node();
if(pos->r==NULL) pos->r = new node();
int mid=(l+r)/2;
down(pos, l, r);
return get(pos->l, l, mid, u, v)+get(pos->r, mid+1, r, u, v);
}
int f(int x)
{
int l=1, r=n, ans=n+1;
while(l<=r)
{
int mid=(l+r)/2;
if(get(root, 1, n, mid, mid)>=x)
{
r=mid-1;
ans=min(ans, mid);
}
else l=mid+1;
}
return ans;
}
void sol()
{
root = new node();
cin >> n >> q;
for(int i=1, x; i<=n; i++) cin >> a[i];
sort(a+1, a+n+1);
for(int i=1; i<=n; i++) update(root, 1, n, i, i, a[i]);
while(q--)
{
char tt;
cin >> tt;
if(tt=='F')
{
int c, h;
cin >> c >> h;
int pos=f(h);
if(pos>n) continue;
int val=min(n, pos+c-1);
int l=f(val);
int r=f(val+1);
int v=val-l+1;
update(root, 1, n, pos, l-1, 1);
update(root, 1, n, r-v, r-1, 1);
}
else
{
int l, r;
cin >> l >> r;
cout << f(r+1)-f(l) << el;
}
}
}
signed main()
{
// freopen("divisor.INP", "r", stdin);
// freopen("divisor.OUT", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
int t=1;
//cin >> t;
while(t--)
{
sol();
}
}
Compilation message
grow.cpp: In function 'void sol()':
grow.cpp:85:18: warning: unused variable 'x' [-Wunused-variable]
85 | for(int i=1, x; i<=n; i++) cin >> a[i];
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
464 ms |
10204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
266 ms |
2160 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
284 ms |
2384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
509 ms |
8016 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
502 ms |
8784 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
569 ms |
9552 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
703 ms |
10300 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
644 ms |
10076 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
579 ms |
12212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |