답안 #991333

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
991333 2024-06-02T05:31:52 Z goats_9 Growing Trees (BOI11_grow) C++17
100 / 100
91 ms 3680 KB
/* Author: goats_9 */

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#define LSOne(s) (s & -(s))

class BIT {
	int n;
	vector<ll> values;

public:
	BIT(int _n) : n(_n), values(n + 1, 0LL) {}

	void update(int l, int r, int v) {
		if (r <= l) return;
		for (; l <= n; l += LSOne(l)) values[l] += v;
		for (; r <= n; r += LSOne(r)) values[r] -= v;
	}

	ll query(int i) {
		if (i > n) return -1;
		ll ret = 0;
		for (; i; i -= LSOne(i)) ret += values[i];
		return ret;
	}
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, q;
	cin >> n >> q;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a.begin(), a.end());
	BIT ft(n);
	for (int i = 0; i < n; i++) ft.update(i + 1, i + 2, a[i]);
	while (q--) {
		char op;
		cin >> op;
		if (op == 'F') {
			int c, h;
			cin >> c >> h;
			int l = 0, r = n + 1;
			while (r - l > 1) {
				int g = (l + r) / 2;
				if (ft.query(g) >= h) r = g;
				else l = g;
			}
			if (r > n) continue;
			if (r + c > n) {
				ft.update(r, r + c, 1);
				continue;
			}
			int u = ft.query(r + c - 1);
			int lt = r;
			l = 0, r = n + 1;
			while (r - l > 1) {
				int g = (l + r) / 2;
				if (ft.query(g) >= u) r = g;
				else l = g;
			}
			int l1 = r;
			l = 0, r = n + 1;
			while (r - l > 1) {
				int g = (l + r) / 2;
				if (ft.query(g) <= u) l = g;
				else r = g;
			}
			ft.update(lt, l1, 1);
			ft.update(r - c + (l1 - lt), r, 1);
		} else {
			int m, M;
			cin >> m >> M;
			int l = 0, r = n + 1;
			while (r - l > 1) {
				int g = (l + r) / 2;
				if (ft.query(g) >= m) r = g;
				else l = g;
			}
			int lt = l;
			l = 0, r = n + 1;
			while (r - l > 1) {
				int g = (l + r) / 2;
				if (ft.query(g) > M) r = g;
				else l = g;
			}
			cout << l - lt << '\n';
		}
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 2712 KB Output is correct
2 Correct 80 ms 3032 KB Output is correct
3 Correct 33 ms 2896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 30 ms 1440 KB Output is correct
6 Correct 37 ms 1624 KB Output is correct
7 Correct 3 ms 348 KB Output is correct
8 Correct 26 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 1812 KB Output is correct
2 Correct 40 ms 1736 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 27 ms 1436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 1876 KB Output is correct
2 Correct 43 ms 1808 KB Output is correct
3 Correct 5 ms 604 KB Output is correct
4 Correct 40 ms 1812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 2388 KB Output is correct
2 Correct 70 ms 2484 KB Output is correct
3 Correct 12 ms 856 KB Output is correct
4 Correct 28 ms 2684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 2236 KB Output is correct
2 Correct 83 ms 2644 KB Output is correct
3 Correct 33 ms 2900 KB Output is correct
4 Correct 12 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 2396 KB Output is correct
2 Correct 54 ms 2676 KB Output is correct
3 Correct 35 ms 2924 KB Output is correct
4 Correct 12 ms 1032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 80 ms 3084 KB Output is correct
2 Correct 74 ms 2644 KB Output is correct
3 Correct 21 ms 2140 KB Output is correct
4 Correct 62 ms 2536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 2888 KB Output is correct
2 Correct 91 ms 3104 KB Output is correct
3 Correct 86 ms 3412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 3680 KB Output is correct