#include <bits/stdc++.h>
using namespace std;
#define ff first
#define sc second
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define pii pair <int, int>
#define ull unsigned long long
// #define int long long
// #define int unsigned long long
const ll inf = 1e18 + 7;
const ll weirdMod = 998244353;
struct node {
int mn, mx;
} t[400040];
int lazy[400040], n, m;
void prop(int v, int tl, int tr) {
t[v].mn += lazy[v];
t[v].mx += lazy[v];
if (tl != tr) {
lazy[2 * v] += lazy[v];
lazy[2 * v + 1] += lazy[v];
} lazy[v] = 0;
}
void set_val(int v, int tl, int tr, int pos, int val) {
if (tl == tr) {
t[v].mx = t[v].mn = val;
return;
} int tm = (tl + tr) / 2;
if (pos <= tm)
set_val(2 * v, tl, tm, pos, val);
else set_val(2 * v + 1, tm + 1, tr, pos, val);
t[v].mn = min(t[2 * v].mn, t[2 * v + 1].mn);
t[v].mx = max(t[2 * v].mx, t[2 * v + 1].mx);
}
int get_val(int v, int tl, int tr, int pos) {
if (lazy[v])
prop(v, tl, tr);
if (tl == tr)
return t[v].mn;
int tm = (tl + tr) / 2;
if (pos <= tm)
return get_val(2 * v, tl, tm, pos);
else return get_val(2 * v + 1, tm + 1, tr, pos);
t[v].mn = min(t[2 * v].mn, t[2 * v + 1].mn);
t[v].mx = max(t[2 * v].mx, t[2 * v + 1].mx);
}
void add_one(int v, int tl, int tr, int l, int r) {
if (lazy[v])
prop(v, tl, tr);
if (tr < l || r < tl)
return;
if (l <= tl && tr <= r) {
t[v].mn++; t[v].mx++;
if (tl != tr) {
lazy[2 * v]++;
lazy[2 * v + 1]++;
} return;
} int tm = (tl + tr) / 2;
add_one(2 * v, tl, tm, l, min(r, tm));
add_one(2 * v + 1, tm + 1, tr, max(l, tm + 1), r);
t[v].mn = min(t[2 * v].mn, t[2 * v + 1].mn);
t[v].mx = max(t[2 * v].mx, t[2 * v + 1].mx);
}
int find_first(int v, int tl, int tr, int val) {
if (lazy[v]) prop(v, tl, tr);
if (t[v].mx < val) return tr + 1;
if (tl == tr) return tl;
int tm = (tl + tr) / 2;
int pos = find_first(2 * v, tl, tm, val), ans;
if (pos == tm + 1)
ans = find_first(2 * v + 1, tm + 1, tr, val);
else ans = pos;
t[v].mn = min(t[2 * v].mn, t[2 * v + 1].mn);
t[v].mx = max(t[2 * v].mx, t[2 * v + 1].mx);
return ans;
}
int find_last(int v, int tl, int tr, int val) {
if (lazy[v]) prop(v, tl, tr);
if (val < t[v].mn) return tl - 1;
if (tl == tr) return tl;
int tm = (tl + tr) / 2;
int pos = find_last(2 * v + 1, tm + 1, tr, val), ans;
if (pos == tm)
ans = find_last(2 * v, tl, tm, val);
else ans = pos;
t[v].mn = min(t[2 * v].mn, t[2 * v + 1].mn);
t[v].mx = max(t[2 * v].mx, t[2 * v + 1].mx);
return ans;
}
void upd_query(int c, int h) {
int pos = find_first(1, 1, n, h);
int num = get_val(1, 1, n, min(n, pos + c - 1));
int l = find_first(1, 1, n, num), r = find_last(1, 1, n, num); c -= l - pos;
add_one(1, 1, n, pos, l - 1); add_one(1, 1, n, max(l, r - c + 1), r);
}
void ans_query(int l, int r) {
l = find_first(1, 1, n, l);
r = find_last(1, 1, n, r);
cout << r - l + 1 << '\n';
}
void solve() {
cin >> n >> m;
vector<int> vec(n);
for (auto &v : vec) cin >> v;
sort(vec.begin(), vec.end());
for (int i = 1; i <= n; i++)
set_val(1, 1, n, i, vec[i - 1]);
char v; int l, r;
for (int i = 1; i <= m; i++) {
cin >> v >> l >> r;
if (v == 'F') upd_query(l, r);
else ans_query(l, r);
}
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
} return 0;
}#include <bits/stdc++.h>
using namespace std;
#define ff first
#define sc second
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define pii pair <int, int>
#define ull unsigned long long
// #define int long long
// #define int unsigned long long
const ll inf = 1e18 + 7;
const ll weirdMod = 998244353;
struct node {
int mn, mx;
} t[400040];
int lazy[400040], n, m;
void prop(int v, int tl, int tr) {
t[v].mn += lazy[v];
t[v].mx += lazy[v];
if (tl != tr) {
lazy[2 * v] += lazy[v];
lazy[2 * v + 1] += lazy[v];
} lazy[v] = 0;
}
void set_val(int v, int tl, int tr, int pos, int val) {
if (tl == tr) {
t[v].mx = t[v].mn = val;
return;
} int tm = (tl + tr) / 2;
if (pos <= tm)
set_val(2 * v, tl, tm, pos, val);
else set_val(2 * v + 1, tm + 1, tr, pos, val);
t[v].mn = min(t[2 * v].mn, t[2 * v + 1].mn);
t[v].mx = max(t[2 * v].mx, t[2 * v + 1].mx);
}
int get_val(int v, int tl, int tr, int pos) {
if (lazy[v])
prop(v, tl, tr);
if (tl == tr)
return t[v].mn;
int tm = (tl + tr) / 2;
if (pos <= tm)
return get_val(2 * v, tl, tm, pos);
else return get_val(2 * v + 1, tm + 1, tr, pos);
t[v].mn = min(t[2 * v].mn, t[2 * v + 1].mn);
t[v].mx = max(t[2 * v].mx, t[2 * v + 1].mx);
}
void add_one(int v, int tl, int tr, int l, int r) {
if (lazy[v])
prop(v, tl, tr);
if (tr < l || r < tl)
return;
if (l <= tl && tr <= r) {
t[v].mn++; t[v].mx++;
if (tl != tr) {
lazy[2 * v]++;
lazy[2 * v + 1]++;
} return;
} int tm = (tl + tr) / 2;
add_one(2 * v, tl, tm, l, min(r, tm));
add_one(2 * v + 1, tm + 1, tr, max(l, tm + 1), r);
t[v].mn = min(t[2 * v].mn, t[2 * v + 1].mn);
t[v].mx = max(t[2 * v].mx, t[2 * v + 1].mx);
}
int find_first(int v, int tl, int tr, int val) {
if (lazy[v]) prop(v, tl, tr);
if (t[v].mx < val) return tr + 1;
if (tl == tr) return tl;
int tm = (tl + tr) / 2;
int pos = find_first(2 * v, tl, tm, val), ans;
if (pos == tm + 1)
ans = find_first(2 * v + 1, tm + 1, tr, val);
else ans = pos;
t[v].mn = min(t[2 * v].mn, t[2 * v + 1].mn);
t[v].mx = max(t[2 * v].mx, t[2 * v + 1].mx);
return ans;
}
int find_last(int v, int tl, int tr, int val) {
if (lazy[v]) prop(v, tl, tr);
if (val < t[v].mn) return tl - 1;
if (tl == tr) return tl;
int tm = (tl + tr) / 2;
int pos = find_last(2 * v + 1, tm + 1, tr, val), ans;
if (pos == tm)
ans = find_last(2 * v, tl, tm, val);
else ans = pos;
t[v].mn = min(t[2 * v].mn, t[2 * v + 1].mn);
t[v].mx = max(t[2 * v].mx, t[2 * v + 1].mx);
return ans;
}
void upd_query(int c, int h) {
int pos = find_first(1, 1, n, h);
int num = get_val(1, 1, n, min(n, pos + c - 1));
int l = find_first(1, 1, n, num), r = find_last(1, 1, n, num); c -= l - pos;
add_one(1, 1, n, pos, l - 1); add_one(1, 1, n, max(l, r - c + 1), r);
}
void ans_query(int l, int r) {
l = find_first(1, 1, n, l);
r = find_last(1, 1, n, r);
cout << r - l + 1 << '\n';
}
void solve() {
cin >> n >> m;
vector<int> vec(n);
for (auto &v : vec) cin >> v;
sort(vec.begin(), vec.end());
for (int i = 1; i <= n; i++)
set_val(1, 1, n, i, vec[i - 1]);
char v; int l, r;
for (int i = 1; i <= m; i++) {
cin >> v >> l >> r;
if (v == 'F') upd_query(l, r);
else ans_query(l, r);
}
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
} return 0;
}
Compilation message
grow.cpp:130:2: error: stray '#' in program
130 | }#include <bits/stdc++.h>
| ^
grow.cpp:130:3: error: 'include' does not name a type
130 | }#include <bits/stdc++.h>
| ^~~~~~~
grow.cpp:144:10: error: redefinition of 'const long long int inf'
144 | const ll inf = 1e18 + 7;
| ^~~
grow.cpp:15:10: note: 'const long long int inf' previously defined here
15 | const ll inf = 1e18 + 7;
| ^~~
grow.cpp:145:10: error: redefinition of 'const long long int weirdMod'
145 | const ll weirdMod = 998244353;
| ^~~~~~~~
grow.cpp:16:10: note: 'const long long int weirdMod' previously defined here
16 | const ll weirdMod = 998244353;
| ^~~~~~~~
grow.cpp:147:8: error: redefinition of 'struct node'
147 | struct node {
| ^~~~
grow.cpp:18:8: note: previous definition of 'struct node'
18 | struct node {
| ^~~~
grow.cpp:149:3: error: conflicting declaration 'int t [400040]'
149 | } t[400040];
| ^
grow.cpp:20:3: note: previous declaration as 'node t [400040]'
20 | } t[400040];
| ^
grow.cpp:150:5: error: redefinition of 'int lazy [400040]'
150 | int lazy[400040], n, m;
| ^~~~
grow.cpp:21:5: note: 'int lazy [400040]' previously declared here
21 | int lazy[400040], n, m;
| ^~~~
grow.cpp:150:19: error: redefinition of 'int n'
150 | int lazy[400040], n, m;
| ^
grow.cpp:21:19: note: 'int n' previously declared here
21 | int lazy[400040], n, m;
| ^
grow.cpp:150:22: error: redefinition of 'int m'
150 | int lazy[400040], n, m;
| ^
grow.cpp:21:22: note: 'int m' previously declared here
21 | int lazy[400040], n, m;
| ^
grow.cpp:151:6: error: redefinition of 'void prop(int, int, int)'
151 | void prop(int v, int tl, int tr) {
| ^~~~
grow.cpp:22:6: note: 'void prop(int, int, int)' previously defined here
22 | void prop(int v, int tl, int tr) {
| ^~~~
grow.cpp:159:6: error: redefinition of 'void set_val(int, int, int, int, int)'
159 | void set_val(int v, int tl, int tr, int pos, int val) {
| ^~~~~~~
grow.cpp:30:6: note: 'void set_val(int, int, int, int, int)' previously defined here
30 | void set_val(int v, int tl, int tr, int pos, int val) {
| ^~~~~~~
grow.cpp:170:5: error: redefinition of 'int get_val(int, int, int, int)'
170 | int get_val(int v, int tl, int tr, int pos) {
| ^~~~~~~
grow.cpp:41:5: note: 'int get_val(int, int, int, int)' previously defined here
41 | int get_val(int v, int tl, int tr, int pos) {
| ^~~~~~~
grow.cpp:182:6: error: redefinition of 'void add_one(int, int, int, int, int)'
182 | void add_one(int v, int tl, int tr, int l, int r) {
| ^~~~~~~
grow.cpp:53:6: note: 'void add_one(int, int, int, int, int)' previously defined here
53 | void add_one(int v, int tl, int tr, int l, int r) {
| ^~~~~~~
grow.cpp:199:5: error: redefinition of 'int find_first(int, int, int, int)'
199 | int find_first(int v, int tl, int tr, int val) {
| ^~~~~~~~~~
grow.cpp:70:5: note: 'int find_first(int, int, int, int)' previously defined here
70 | int find_first(int v, int tl, int tr, int val) {
| ^~~~~~~~~~
grow.cpp:212:5: error: redefinition of 'int find_last(int, int, int, int)'
212 | int find_last(int v, int tl, int tr, int val) {
| ^~~~~~~~~
grow.cpp:83:5: note: 'int find_last(int, int, int, int)' previously defined here
83 | int find_last(int v, int tl, int tr, int val) {
| ^~~~~~~~~
grow.cpp:225:6: error: redefinition of 'void upd_query(int, int)'
225 | void upd_query(int c, int h) {
| ^~~~~~~~~
grow.cpp:96:6: note: 'void upd_query(int, int)' previously defined here
96 | void upd_query(int c, int h) {
| ^~~~~~~~~
grow.cpp:231:6: error: redefinition of 'void ans_query(int, int)'
231 | void ans_query(int l, int r) {
| ^~~~~~~~~
grow.cpp:102:6: note: 'void ans_query(int, int)' previously defined here
102 | void ans_query(int l, int r) {
| ^~~~~~~~~
grow.cpp:236:6: error: redefinition of 'void solve()'
236 | void solve() {
| ^~~~~
grow.cpp:107:6: note: 'void solve()' previously defined here
107 | void solve() {
| ^~~~~
grow.cpp:250:9: error: redefinition of 'int32_t main()'
250 | int32_t main() {
| ^~~~
grow.cpp:121:9: note: 'int32_t main()' previously defined here
121 | int32_t main() {
| ^~~~