This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
grow.cpp: In function 'int main()':
grow.cpp:140:8: warning: unused variable 'temp' [-Wunused-variable]
140 | int temp = c;
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |