Submission #879482

# Submission time Handle Problem Language Result Execution time Memory
879482 2023-11-27T14:17:42 Z OAleksa Growing Trees (BOI11_grow) C++14
10 / 100
82 ms 8788 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f first
#define s second
const int maxn = 1e5 + 69;
int st[4 * maxn], n, q, a[maxn], lz[4 * maxn];
void push(int v) {
	if (lz[v]) {
		st[v * 2] += lz[v];
		st[v * 2 + 1] += lz[v];
		lz[v * 2] += lz[v];
		lz[v * 2 + 1] += lz[v];
		lz[v] = 0;
	}
}
void build(int v, int tl, int tr) {
	if (tl == tr)
		st[v] = a[tl];
	else {
		int mid = (tl + tr) / 2;
		build(v * 2, tl, mid);
		build(v * 2 + 1, mid + 1, tr);
		st[v] = max(st[v * 2], st[v * 2 + 1]);
	}
}
void upd(int v, int tl, int tr, int l, int r) {
	if (tl > r || tr < l)
		return;
	else if (tl >= l && tr <= r) {
		st[v]++;
		lz[v]++;
	}
	else {
		int mid = (tl + tr) / 2;
		push(v);
		upd(v * 2, tl, mid, l, r);
		upd(v * 2 + 1, mid + 1, tr, l, r);
		st[v] = max(st[v * 2], st[v * 2 + 1]);
	}
}
int qry(int v, int tl, int tr, int x) {
	if (tl == tr)
		return tl;
	else {
		push(v);
		int mid = (tl + tr) / 2;
		if (st[v * 2] >= x)
			return qry(v * 2, tl, mid, x);
		else
			return qry(v * 2 + 1, mid + 1, tr, x);
	}
}
int qryind(int v, int tl, int tr, int p) {
	if (tl == tr)
		return st[v];
	else {
		push(v);
		int mid = (tl + tr) / 2;
		if (mid >= p)
			return qryind(v * 2, tl, mid, p);
		else
			return qryind(v * 2 + 1, mid + 1, tr, p);
	}
}
signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
   int tt = 1;
  	//cin >> tt;
   while (tt--) {
   	cin >> n >> q;
   	++n;
   	a[n] = 1e18;
   	for (int i = 1;i < n;i++)
   		cin >> a[i];
   	sort(a + 1, a + n + 1);
   	build(1, 1, n);
   	while (q--) {
   		char t;
   		cin >> t;
   		if (t == 'F') {
   			int c, h;
   			cin >> c >> h;
   			int l = qry(1, 1, n, h);
   			int r = min(n, l + c - 1);
   			int x = qryind(1, 1, n, r);
   			int y = qryind(1, 1, n, r + 1);
   			if (x == y) {
   				int z = max(l, qry(1, 1, n, x));
   				int raz = r - z + 1;
   				int p = qry(1, 1, n, x + 1);
   				if (z > l)
   					upd(1, 1, n, l, z - 1);
   				upd(1, 1, n, p - raz, p - 1);
   			}
   			else
   				upd(1, 1, n, l, r);
   		}
   		else {
   			int l, r;
   			cin >> l >> r;
   			cout << max(0ll, qry(1, 1, n, r + 1) - qry(1, 1, n, l)) << '\n';
   		}
   	}
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 52 ms 7668 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2516 KB Output is correct
2 Correct 2 ms 2392 KB Output is correct
3 Correct 2 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Incorrect 30 ms 3672 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 3776 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 3928 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 48 ms 6656 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 69 ms 7692 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 45 ms 7504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 82 ms 8272 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 62 ms 7992 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 59 ms 8788 KB Output is correct