#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
#define foru(i, l, r) for(int i=(l); i<=(r); ++i)
#define ford(i, l, r) for(int i=(l); i>=(r); --i)
#define fore(x, v) for(auto &x : v)
#define fi first
#define se second
void setIO(string name) {
if (!name.empty()) {
freopen((name + ".in").c_str(), "r", stdin);
freopen((name + ".out").c_str(), "w", stdout);
}
}
const int N = 1e5+5;
const int LOG = 17;
int n, m, a[N], bit[N];
void modify(int i, int v) {
for(; i<=n; i+=i&-i) bit[i] += v;
}
int query(int i) {
int ans = 0;
for(; i>=1; i-=i&-i) ans += bit[i];
return ans;
}
void inc(int l, int r, int val) {
modify(l, val);
modify(r+1, -val);
}
int lst(int val) {
int cur = 0, till = 0;
for(int i=LOG-1; i>=0; --i)
if (cur+(1<<i) <= n && till+bit[cur+(1<<i)] <= val)
cur += 1 << i, till += bit[cur];
return cur;
}
void solve () {
cin >> n >> m;
foru(i, 1, n) cin >> a[i];
sort(a+1, a+n+1);
foru(i, 1, n) modify(i, a[i] - a[i-1]);
foru(i, 1, m) {
char cmd;
cin >> cmd;
if (cmd == 'F') {
int c, h;
cin >> c >> h;
int lb = lst(h-1)+1, alpha = min(n, lb+c-1);
int mx_value = query(alpha);
int rb = lst(mx_value), rx = lst(mx_value-1);
inc(lb, rx, 1);
int lx = max(rx+1, rb - (c - (rx-lb+1)) + 1);
inc(lx, rb, 1);
}
else {
int mn, mx;
cin >> mn >> mx;
cout << lst(mx) - lst(mn-1) << "\n";
}
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
setIO("");
solve();
}
Compilation message
grow.cpp: In function 'void setIO(std::string)':
grow.cpp:14:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | freopen((name + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
grow.cpp:15:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
15 | freopen((name + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
2332 KB |
Output is correct |
2 |
Correct |
47 ms |
2680 KB |
Output is correct |
3 |
Correct |
33 ms |
2608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
372 KB |
Output is correct |
5 |
Correct |
23 ms |
1388 KB |
Output is correct |
6 |
Correct |
26 ms |
1612 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
19 ms |
1180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
1656 KB |
Output is correct |
2 |
Correct |
25 ms |
1700 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
21 ms |
1312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
1856 KB |
Output is correct |
2 |
Correct |
27 ms |
1620 KB |
Output is correct |
3 |
Correct |
4 ms |
468 KB |
Output is correct |
4 |
Correct |
25 ms |
1748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
1892 KB |
Output is correct |
2 |
Correct |
48 ms |
2264 KB |
Output is correct |
3 |
Correct |
8 ms |
836 KB |
Output is correct |
4 |
Correct |
29 ms |
2276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
1996 KB |
Output is correct |
2 |
Correct |
40 ms |
2344 KB |
Output is correct |
3 |
Correct |
33 ms |
2432 KB |
Output is correct |
4 |
Correct |
8 ms |
852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
2232 KB |
Output is correct |
2 |
Correct |
33 ms |
2264 KB |
Output is correct |
3 |
Correct |
35 ms |
2644 KB |
Output is correct |
4 |
Correct |
10 ms |
852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
2720 KB |
Output is correct |
2 |
Correct |
40 ms |
2272 KB |
Output is correct |
3 |
Correct |
17 ms |
1808 KB |
Output is correct |
4 |
Correct |
37 ms |
2204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
2436 KB |
Output is correct |
2 |
Correct |
50 ms |
2588 KB |
Output is correct |
3 |
Correct |
54 ms |
2864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
3396 KB |
Output is correct |