# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
372855 |
2021-03-02T04:20:44 Z |
8e7 |
Growing Trees (BOI11_grow) |
C++14 |
|
187 ms |
3308 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], seg[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] > 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 r;
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
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
87 ms |
2796 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
57 ms |
748 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
46 ms |
748 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
113 ms |
1772 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
166 ms |
2892 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
115 ms |
2796 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
187 ms |
3052 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
166 ms |
2924 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
128 ms |
3308 KB |
Output isn't correct |