답안 #372858

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
372858 2021-03-02T04:29:26 Z 8e7 Growing Trees (BOI11_grow) C++14
0 / 100
144 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] + 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 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, max(n - 1, 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
 */
# 결과 실행 시간 메모리 Grader output
1 Incorrect 96 ms 2924 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 40 ms 748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 42 ms 748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 84 ms 1772 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 100 ms 2924 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 85 ms 2924 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 144 ms 3052 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 104 ms 2924 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 122 ms 3308 KB Output isn't correct