#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);
}
void sol()
{
root = new node();
cin >> n >> q;
for(int i=1, x;i<=n;i++)
{
cin >> x;
update(root, 1, 1e9, x, x, 1);
}
while(q--)
{
char tt;
cin >> tt;
if(tt=='F')
{
int c, h;
cin >> c >> h;
int l=h, r=1e9, ans=1e9;
while(l<=r)
{
int mid=(l+r)/2;
if(get(root, 1, 1e9, h, mid)>0)
{
r=mid-1;
ans=min(ans, mid);
}
else l=mid+1;
}
// cout << ans << el;
update(root, 1, 1e9, ans, ans, -1);
if(ans+c<=1e9) update(root, 1, 1e9, ans+c, ans+c, 1);
}
else
{
int l, r;
cin >> l >> r;
cout << get(root, 1, 1e9, l, r) << 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();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
328 ms |
23016 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
87 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
97 ms |
5968 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
371 ms |
7248 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
442 ms |
7768 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
428 ms |
10160 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
891 ms |
84844 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
364 ms |
6736 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
141 ms |
18732 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |