#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 lower (int id, int l, int r, int val) {
down(id);
if (l == r) return l;
int mid = l + r >> 1;
if (node[id*2] >= val) return lower(id*2, l, mid, val);
else return lower(id*2+1, mid+1, r, val);
}
int upper (int id, int l, int r, int val) {
down(id);
if (l == r) return l;
int mid = l + r >> 1;
if (node[id*2+1] <= val) return upper(id*2+1,mid+1,r,val);
else return upper(id*2,l,mid,val);
}
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 lower (int val) {
return lower(1,1,n,val);
}
int upper (int val) {
return upper(1,1,n,val);
}
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 = st.lower(v);
if(l1 == -1) continue;
int r1 = min(n , l1 + u - 1);
int MAX = st.get(r1);
int l2 = st.lower(MAX);
int r2 = st.upper(MAX);
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);
}
} else {
int l, r; cin >> l >> r;
int L = st.lower(l);
int R = st.upper(r);
if (st.get(L) > r || st.get(R) < l) 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::lower(int, int, int, int)':
grow.cpp:71:24: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
71 | int mid = l + r >> 1;
| ~~^~~
grow.cpp: In member function 'int Stree::upper(int, int, int, int)':
grow.cpp:79:24: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
79 | int mid = l + r >> 1;
| ~~^~~
grow.cpp: In member function 'int Stree::get(int, int, int, int)':
grow.cpp:87:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
87 | 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:130:7: note: in expansion of macro 'file'
130 | 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:130:7: note: in expansion of macro 'file'
130 | file("dynamic");
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
30 ms |
8792 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
24 ms |
4748 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
25 ms |
4896 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
29 ms |
8796 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
34 ms |
8872 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
34 ms |
8880 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
67 ms |
8920 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
39 ms |
8792 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
53 ms |
9144 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |