#include <bits/stdc++.h>
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using cd = complex <double>;
typedef pair <int, int> pii;
const long long INF = 1e18;
const int mod = 1e9 + 7;//1e9 + 7;//786433;//998244353;
const double Pi = acos(-1);
void Fastio()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
int n, m;
int a[100005], b[100005];
int ST[400005], lazy[400005];
void Build(int node, int l, int r)
{
if(l == r)
{
ST[node] = a[l];
a[l] = node;
return;
}
int mid = (l + r) >> 1;
Build(node << 1, l, mid);
Build(node << 1 | 1, mid + 1, r);
ST[node] = max(ST[node << 1], ST[node << 1 | 1]);
}
void Push(int node, int l, int r)
{
if(lazy[node])
{
if(l != r)
{
lazy[node << 1] += lazy[node];
lazy[node << 1 | 1] += lazy[node];
}
ST[node] += lazy[node];
lazy[node] = 0;
}
}
void Update(int node, int l, int r, int L, int R)
{
Push(node, l, r);
if(R < l or r < L or L > R)
{
return;
}
if(l >= L and r <= R)
{
lazy[node]++;
Push(node, l, r);
return;
}
int mid = (l + r) >> 1;
Update(node << 1, l, mid, L, R);
Update(node << 1 | 1, mid + 1, r, L, R);
ST[node] = max(ST[node << 1], ST[node << 1 | 1]);
}
int TrueVal(int node, int l, int r)
{
Push(node, l, r);
return ST[node];
}
int Search(int node, int l, int r, int val)
{
Push(node, l, r);
if(ST[1] < val)
{
return n + 1;
}
if(l == r)
{
return r;
}
int mid = (l + r) >> 1;
if(TrueVal(node << 1, l, mid) >= val)
{
return Search(node << 1, l, mid, val);
}
return Search(node << 1 | 1, mid + 1, r, val);
}
signed main()
{
Fastio();
cin >> n >> m;
for(int i = 1; i <= n; i++)
{
cin >> a[i];
}
sort(a + 1, a + n + 1);
for(int i = 1; i <= n; i++)
{
b[i] = a[i];
}
Build(1, 1, n);
while(m--)
{
char type;
cin >> type;
if(type == 'F')
{
int c, h;
cin >> c >> h;
for(int i = 18; i > 0; i--)
{
Push(a[1] >> i, 1, 2);
}
Push(a[1], 1, 1);
int l = Search(1, 1, n, h);
if(l + c - 1 > n)
{
Update(1, 1, n, l, n);
for(int i = l; i <= n; i++)
{
b[i]++;
}
continue;
}
int r = l + c - 1;
for(int i = 18; i > 0; i--)
{
Push(a[r] >> i, 1, 2);
}
Push(a[r], r, r);
int temp = c;
// ST[a[r]]
int ll = Search(1, 1, n, ST[a[r]]), rr = Search(1, 1, n, ST[a[r]] + 1);
Update(1, 1, n, l, ll - 1);
c -= (ll - l);
Update(1, 1, n, rr - c, rr - 1);
}
else
{
int l, r;
cin >> l >> r;
cout << Search(1, 1, n, r + 1) - Search(1, 1, n, l) << '\n';
}
}
}
Compilation message
grow.cpp: In function 'int main()':
grow.cpp:140:8: warning: unused variable 'temp' [-Wunused-variable]
140 | int temp = c;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
109 ms |
4512 KB |
Output is correct |
2 |
Correct |
277 ms |
4824 KB |
Output is correct |
3 |
Correct |
316 ms |
4816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
512 KB |
Output is correct |
3 |
Correct |
3 ms |
512 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
50 ms |
1656 KB |
Output is correct |
6 |
Correct |
64 ms |
1784 KB |
Output is correct |
7 |
Correct |
6 ms |
640 KB |
Output is correct |
8 |
Correct |
34 ms |
1348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
1784 KB |
Output is correct |
2 |
Correct |
60 ms |
1912 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
42 ms |
1528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
2040 KB |
Output is correct |
2 |
Correct |
69 ms |
1952 KB |
Output is correct |
3 |
Correct |
11 ms |
640 KB |
Output is correct |
4 |
Correct |
61 ms |
1912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
3064 KB |
Output is correct |
2 |
Correct |
238 ms |
4344 KB |
Output is correct |
3 |
Correct |
17 ms |
1424 KB |
Output is correct |
4 |
Correct |
239 ms |
4472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
146 ms |
4216 KB |
Output is correct |
2 |
Correct |
229 ms |
4472 KB |
Output is correct |
3 |
Correct |
290 ms |
4744 KB |
Output is correct |
4 |
Correct |
17 ms |
1408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
95 ms |
4200 KB |
Output is correct |
2 |
Correct |
114 ms |
4524 KB |
Output is correct |
3 |
Correct |
313 ms |
4736 KB |
Output is correct |
4 |
Correct |
17 ms |
1408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
293 ms |
4856 KB |
Output is correct |
2 |
Correct |
160 ms |
4348 KB |
Output is correct |
3 |
Correct |
64 ms |
3960 KB |
Output is correct |
4 |
Correct |
83 ms |
4344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
114 ms |
4756 KB |
Output is correct |
2 |
Correct |
166 ms |
4728 KB |
Output is correct |
3 |
Correct |
208 ms |
5112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
106 ms |
5496 KB |
Output is correct |