# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
372859 |
2021-03-02T04:30:18 Z |
8e7 |
Growing Trees (BOI11_grow) |
C++14 |
|
258 ms |
4716 KB |
//Challenge: Accepted
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <stack>
#define ll long long
#define maxn 200005
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
int a[maxn], seg[4 * maxn], tag[4 * maxn];
void push(int cur, int l, int r) {
seg[cur] += tag[cur];
if (r - l > 1) {
tag[cur * 2] += tag[cur];
tag[cur * 2 + 1] += tag[cur];
}
tag[cur] = 0;
}
void modify(int cur, int l, int r, int ql, int qr, int val) {
if (r <= l || qr <= l || ql >= r) return;
push(cur, l, r);
if (ql <= l && qr >= r) {
tag[cur] += val;
push(cur, l, r);
return;
}
int mid = (l + r) / 2;
modify(cur * 2, l, mid, ql, qr, val);
modify(cur * 2 + 1, mid, r, ql, qr, val);
seg[cur] = max(seg[cur * 2] + tag[cur * 2], seg[cur * 2 + 1] + tag[cur * 2 + 1]);
}
int query(int cur, int l, int r, int x) { //number of things <= x in range [l, r)
if (r <= l) return 0;
push(cur, l, r);
if (seg[cur] <= x) return r - l;
if (r - l == 1) return 0;
int mid = (l + r) / 2;
if (seg[cur * 2] + tag[cur * 2] > x) return query(cur * 2, l, mid, x);
else return query(cur * 2, l, mid, x) + query(cur * 2 + 1, mid, r, x);
}
int getval(int cur, int l, int r, int ind) {
if (r <= l) return 0;
if (ind >= r) return 1<<30;
push(cur, l, r);
if (r - l == 1) return seg[cur];
int mid = (l + r) / 2;
if (ind < mid) return getval(cur * 2, l, mid, ind);
else return getval(cur * 2 + 1, mid, r, ind);
}
int main() {
io
int n, m;
cin >> n >> m;
for (int i = 0;i < n;i++) cin >> a[i];
sort(a, a + n);
for (int i = 0;i < n;i++) {
modify(1, 0, n, i, i + 1, a[i]);
}
while (m--) {
char type;
cin >> type;
if (type == 'F') {
int ci, hi;
cin >> ci >> hi;
int lef = query(1, 0, n, hi - 1);
int val = getval(1, 0, n, lef + ci - 1);
int rig = query(1, 0, n, val - 1), r2 = query(1, 0, n, val);
//cout << lef << " " << rig << endl;
modify(1, 0, n, lef, rig, 1);
int cnt = ci - (rig - lef);
//cout << r2 - cnt << " " << r2 << endl;
modify(1, 0, n, max(rig, r2 - cnt), r2, 1);
//for (int i = 0;i < n;i++) cout << getval(1, 0, n, i) << " ";
//cout << endl;
} else {
int mi, ma;
cin >> mi >> ma;
cout << query(1, 0, n, ma) - query(1, 0, n, mi - 1) << "\n";
}
}
}
/*
5 7
1 3 2 5 2
F 2 1
C 3 6
F 2 3
C 6 8
F 2 1
F 2 2
C 3 5
7 10
1 2 2 4 4 5 6
F 4 3
F 3 2
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
106 ms |
3052 KB |
Output is correct |
2 |
Correct |
187 ms |
2924 KB |
Output is correct |
3 |
Correct |
145 ms |
4460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
3 ms |
364 KB |
Output is correct |
3 |
Correct |
3 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
5 |
Correct |
51 ms |
1644 KB |
Output is correct |
6 |
Correct |
67 ms |
1772 KB |
Output is correct |
7 |
Correct |
6 ms |
748 KB |
Output is correct |
8 |
Correct |
31 ms |
1260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
876 KB |
Output is correct |
2 |
Correct |
59 ms |
876 KB |
Output is correct |
3 |
Correct |
4 ms |
620 KB |
Output is correct |
4 |
Correct |
39 ms |
1516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
1132 KB |
Output is correct |
2 |
Correct |
69 ms |
876 KB |
Output is correct |
3 |
Correct |
12 ms |
492 KB |
Output is correct |
4 |
Correct |
59 ms |
876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
103 ms |
1884 KB |
Output is correct |
2 |
Correct |
149 ms |
2924 KB |
Output is correct |
3 |
Correct |
21 ms |
1132 KB |
Output is correct |
4 |
Correct |
117 ms |
2668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
130 ms |
2940 KB |
Output is correct |
2 |
Correct |
142 ms |
2924 KB |
Output is correct |
3 |
Correct |
136 ms |
2668 KB |
Output is correct |
4 |
Correct |
21 ms |
1388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
119 ms |
2924 KB |
Output is correct |
2 |
Correct |
110 ms |
2924 KB |
Output is correct |
3 |
Correct |
141 ms |
2924 KB |
Output is correct |
4 |
Correct |
24 ms |
1388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
162 ms |
2924 KB |
Output is correct |
2 |
Correct |
146 ms |
4076 KB |
Output is correct |
3 |
Correct |
61 ms |
3564 KB |
Output is correct |
4 |
Correct |
102 ms |
4076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
133 ms |
3052 KB |
Output is correct |
2 |
Correct |
147 ms |
2924 KB |
Output is correct |
3 |
Correct |
258 ms |
4716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
123 ms |
3436 KB |
Output is correct |