#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#define file(name) if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
#define ll long long
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, a, b) for (int i = (a); i >= (b); --i)
#define pi pair<int,int>
#define ple tuple<int,int,int>
#define fi first
#define se second
#define ii make_pair
#define isz(a) ((int)a.size())
#define ALL(a) a.begin(), a.end()
#define heap_max(a) priority_queue<a>
#define heap_max(a) priority_queue<a,vector<a>,greater<a>>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T>
//using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
const int N = 1e6 + 10;
int n, a[N], q;
struct Stree {
int node[N * 4], lazy[N * 4];
void fix (int id) {
node[id] = max(node[id*2], node[id*2+1]);
}
void build (int id , int l , int r ) {
if (l == r) {
node[id] = a[l];
return;
}
int mid = l + r >> 1;
build(id*2, l, mid);
build(id*2+1, mid+1, r);
fix(id);
}
void down (int id) {
if (lazy[id] == 0) return;
node[id] += lazy[id];
lazy[id*2] += lazy[id];
lazy[id*2+1] += lazy[id];
lazy[id] = 0;
}
void update (int id, int l, int r, int u, int v) {
down(id);
if (l > v || r < u) return;
if (l >= u && r <= v) {
lazy[id] = 1;
down(id);
return;
}
int mid = l + r >> 1;
update(id*2, l, mid, u, v);
update(id*2+1, mid+1, r, u, v);
fix(id);
}
int get (int id, int l, int r, int u) {
down(id);
if (l == r) {return node[id]; }
int mid = l + r >> 1;
if (u <= mid) return get(id*2,l,mid,u);
else return get(id*2+1,mid+1,r,u);
}
int get (int u) {
return get(1,1,n,u);
}
void update (int l, int r) {
update(1,1,n,l,r);
}
} st;
int lower (int val) {
int l = 1, r = n, res = -1;
while (l <= r) {
int mid = l + r >> 1;
if (st.get(mid) >= val) {
res = mid;
r = mid - 1;
} else l = mid + 1;
}
return res;
}
int upper (int val) {
int l = 1, r = n, res = -1;
while (l <= r) {
int mid = l + r >> 1;
if (st.get(mid) <= val) {
res = mid;
l = mid + 1;
} else r = mid - 1;
}
return res;
}
int main () {
file("dynamic");
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> q;
FOR(i,1,n) cin >> a[i];
FOR(i,0,4*n) st.lazy[i] = 0;
sort(a+1, a+n+1);
st.build(1,1,n);
FOR(d,1,q) {
char type; cin >> type;
if (type == 'F') {
int u, v; cin >> u >> v;
int l1 = lower(v);
if(l1 == -1) continue;
int r1 = min(n , l1 + u - 1);
int l2 = lower(st.get(r1));
int r2 = upper(st.get(r1));
if(l1 <= l2 - 1) {
st.update(l1 , l2 - 1);
}
int tmp = max(l2 , r2 - u + (l2 - l1) + 1);
if(tmp <= r2) {
st.update(tmp , r2);
}
// int c, h; cin >> c >> h;
// int fr1 = lower(h);
// if (fr1 == -1) continue;
// int the_max = st.get(min(n, fr1+c-1));
// int lst1 = upper(the_max - 1);
// lst1 = min({n, lst1, fr1 + c - 1});
// int lst2 = upper(the_max);
//// if(d==3) {
//// for (int i= 1; i <= n; ++i) cout << st.get(i) << ' ';
//// cout << endl;
//// }
// if (fr1 <= lst1) {
// st.update(fr1, lst1);
// }
// int used = lst1-fr1+1;
// c -= used;
// if (c <= 0) continue;
// int fr2 = max(lst1 + 1, lst2 - c + 1);
// if (fr2 <= lst2) {
// st.update(fr2, lst2);
// }
//// if (d==3) {
//// cout << fr1 << ' ' << lst1 << endl;
//// cout << fr2 << ' ' << lst2 << endl;
//// }
//// if(d==3) {
//// for (int i= 1; i <= n; ++i) cout << st.get(i) << ' ';
//// cout << endl;
//// exit(0);
//// }
} else {
int l, r; cin >> l >> r;
int L = lower(l);
int R = upper(r);
if (R==-1||L==-1) cout << 0 << '\n';
else cout << R-L+1 << '\n';
}
}
}
Compilation message
grow.cpp:16: warning: "heap_max" redefined
16 | #define heap_max(a) priority_queue<a,vector<a>,greater<a>>
|
grow.cpp:15: note: this is the location of the previous definition
15 | #define heap_max(a) priority_queue<a>
|
grow.cpp: In member function 'void Stree::build(int, int, int)':
grow.cpp:40:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
40 | int mid = l + r >> 1;
| ~~^~~
grow.cpp: In member function 'void Stree::update(int, int, int, int, int)':
grow.cpp:62:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
62 | int mid = l + r >> 1;
| ~~^~~
grow.cpp: In member function 'int Stree::get(int, int, int, int)':
grow.cpp:71:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
71 | int mid = l + r >> 1;
| ~~^~~
grow.cpp: In function 'int lower(int)':
grow.cpp:86:24: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
86 | int mid = l + r >> 1;
| ~~^~~
grow.cpp: In function 'int upper(int)':
grow.cpp:98:24: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
98 | int mid = l + r >> 1;
| ~~^~~
grow.cpp: In function 'int main()':
grow.cpp:4:60: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
4 | #define file(name) if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
grow.cpp:108:7: note: in expansion of macro 'file'
108 | file("dynamic");
| ^~~~
grow.cpp:4:94: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
4 | #define file(name) if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
grow.cpp:108:7: note: in expansion of macro 'file'
108 | file("dynamic");
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
163 ms |
8920 KB |
Output is correct |
2 |
Correct |
290 ms |
8952 KB |
Output is correct |
3 |
Correct |
200 ms |
8796 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4440 KB |
Output is correct |
2 |
Correct |
3 ms |
4444 KB |
Output is correct |
3 |
Correct |
4 ms |
4580 KB |
Output is correct |
4 |
Correct |
2 ms |
4444 KB |
Output is correct |
5 |
Correct |
105 ms |
4692 KB |
Output is correct |
6 |
Correct |
132 ms |
4928 KB |
Output is correct |
7 |
Correct |
9 ms |
4440 KB |
Output is correct |
8 |
Correct |
54 ms |
4668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
99 ms |
4760 KB |
Output is correct |
2 |
Correct |
130 ms |
4944 KB |
Output is correct |
3 |
Correct |
2 ms |
4444 KB |
Output is correct |
4 |
Correct |
71 ms |
4668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
89 ms |
4948 KB |
Output is correct |
2 |
Correct |
146 ms |
4944 KB |
Output is correct |
3 |
Correct |
17 ms |
4444 KB |
Output is correct |
4 |
Correct |
130 ms |
4980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
162 ms |
9200 KB |
Output is correct |
2 |
Correct |
282 ms |
8968 KB |
Output is correct |
3 |
Correct |
36 ms |
6804 KB |
Output is correct |
4 |
Correct |
156 ms |
8824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
238 ms |
8792 KB |
Output is correct |
2 |
Correct |
282 ms |
8796 KB |
Output is correct |
3 |
Correct |
191 ms |
8812 KB |
Output is correct |
4 |
Correct |
34 ms |
6824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
156 ms |
8948 KB |
Output is correct |
2 |
Correct |
193 ms |
9288 KB |
Output is correct |
3 |
Correct |
187 ms |
8796 KB |
Output is correct |
4 |
Correct |
34 ms |
6944 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
289 ms |
8904 KB |
Output is correct |
2 |
Correct |
278 ms |
9204 KB |
Output is correct |
3 |
Correct |
46 ms |
8836 KB |
Output is correct |
4 |
Correct |
143 ms |
8852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
219 ms |
9048 KB |
Output is correct |
2 |
Correct |
274 ms |
8796 KB |
Output is correct |
3 |
Correct |
358 ms |
8820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
229 ms |
9300 KB |
Output is correct |