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 taskname "test"
#define fi first
#define se second
#define pb push_back
#define faster ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
using ll = long long;
using pii = pair <int, int>;
using pil = pair <int, ll>;
using pli = pair <ll, int>;
using pll = pair <ll, ll>;
using ull = unsigned ll;
mt19937 Rand(chrono::steady_clock::now().time_since_epoch().count());
ll min(const ll &a, const ll &b){
return (a < b) ? a : b;
}
ll max(const ll &a, const ll &b){
return (a > b) ? a : b;
}
//const ll Mod = 1000000009;
//const ll Mod2 = 999999999989;
//only use when required
const int maxN = 1e5 + 1;
int n, m;
int bit[maxN];
int a[maxN];
void update(int x, int val){
for (; x <= n; x += x & -x){
bit[x] += val;
}
}
int get(int x){
int ans = 0;
for (; x; x -= x & -x){
ans += bit[x];
}
return ans;
}
void updatehigh(int x, int y){
int l = 1, r = n;
while (l <= r){
int mid = (l + r) / 2;
if (get(mid) < y) l = mid + 1;
else r = mid - 1;
}
++r;
if (r + x - 1 >= n){
update(r, 1);
return;
}
int need = x;
x = r + x - 1;
int s = r;
int z = get(x);
l = r; r = x;
while (l <= r){
int mid = (l + r) / 2;
if (get(mid) != z) l = mid + 1;
else r = mid - 1;
}
int ll = r + 1;
l = x; r = n;
while (l <= r){
int mid = (l + r) / 2;
if (get(mid) != z) r = mid - 1;
else l = mid + 1;
}
int rr = r + 1;
if (ll != s){
update(s, 1);
update(ll, -1);
}
update(rr - (need - (ll - s)), 1);
update(rr, -1);
}
int getlow(int x){
int l = 1, r = n;
while (l <= r){
int mid = (l + r) / 2;
if (get(mid) < x) l = mid + 1;
else r = mid - 1;
}
//cerr << r << " " << x << "?\n";
return r;
}
int gethigh(int x){
int l = 1, r = n;
while (l <= r){
int mid = (l + r) / 2;
if (get(mid) <= x) l = mid + 1;
else r = mid - 1;
}
//cerr << r << " " << x << "!\n";
return r;
}
void Init(){
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) update(i, a[i] - a[i - 1]);
while (m--){
/*for (int i = 1; i <= n; ++i) cerr << get(i) << " ";
cerr << "\n";*/
char c; cin >> c;
if (c == 'F'){
int x, y;
cin >> x >> y;
updatehigh(x, y);
}
else{
int l, r;
cin >> l >> r;
cout << gethigh(r) - getlow(l) << "\n";
}
}
}
int main(){
if (fopen(taskname".inp", "r")){
freopen(taskname".inp", "r", stdin);
freopen(taskname".out", "w", stdout);
}
faster;
ll tt = 1;
//cin >> tt;
while (tt--){
Init();
}
}
Compilation message (stderr)
grow.cpp: In function 'int main()':
grow.cpp:135:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
135 | freopen(taskname".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
grow.cpp:136:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
136 | freopen(taskname".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |