Submission #954644

# Submission time Handle Problem Language Result Execution time Memory
954644 2024-03-28T09:26:51 Z Amaarsaa Growing Trees (BOI11_grow) C++14
0 / 100
378 ms 12452 KB
#include<bits/stdc++.h>

using namespace std;
#define lc (p<<1)
#define rc (p<<1) + 1
using ll = long long ;
const ll N = 1e5 + 4;
pair < ll, ll > P[N];
ll a[N], n;

struct node {
	ll lzadd;
	ll min;
};
node tree[8 * N + 2];

void pushdown(ll p, ll lo, ll hi) {
	if ( tree[p].lzadd != 0) {
		tree[lc].lzadd += tree[p].lzadd;
		tree[lc].min += tree[p].lzadd;
		tree[rc].lzadd += tree[p].lzadd;
		tree[rc].min += tree[p].lzadd;
		tree[p].lzadd = 0;
	}
	return ;
}

void pushup(ll p, ll lo, ll hi) {
	tree[p].min = min(tree[lc].min, tree[rc].min);
}

void Build (ll p, ll lo, ll hi) {
	ll mid = (lo + hi)/2;
	tree[p].lzadd = 0;
	if ( lo == hi) {
		tree[p].min = a[lo];
		return ;
	}
	Build(lc, lo, mid);
	Build(rc, mid + 1, hi);
	pushup(p, lo, hi);
	return ;
}
ll find(ll p, ll lo, ll hi, ll x) {
	ll mid = (lo + hi)/2;
	pushdown(p, lo, hi);
	if ( lo == hi) return tree[p].min;
	if ( x <= mid) return find(lc, lo, mid, x);
	return find(rc, mid + 1, hi, x);
}
void update(ll p, ll lo, ll hi, ll l, ll r, ll x) {
	if ( lo > hi) return ;
	ll mid = (lo + hi)/2;
	pushdown(p, lo, hi);
	if ( lo > r || l > hi) return ;
	if ( l <= lo && hi <= r) {
		tree[p].lzadd = x;
		tree[p].min += x;
		return ;
	}
	update(lc, lo, mid, l, r, x);
	update(rc, mid + 1, hi, l, r, x);
	pushup(p, lo, hi);
}
ll lowerb(ll x) {
	ll lo, hi, mid;
	lo = 1;
	hi = n + 1;
	while ( lo < hi) {
		mid = (lo + hi)/2;
		if (find(1, 1, n + 1, mid) < x) lo = mid + 1;
		else hi =mid;
	}
	return lo;
}
ll upperb(ll x) {
	ll lo, hi, mid;
	lo = 1;
	hi = n + 1;
	while ( lo < hi) {
		mid = (lo + hi)/2;
		if (find(1, 1, n + 1, mid) <= x) lo = mid + 1;
		else hi =mid;
	}
	return lo;
}
int main() {
//	freopen("moocast.in", "r", stdin);
//	freopen("moocast.out", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	ll q, i, x, l, y, j, s;
	
	cin >> n >> q;
	
	for (i = 1; i <= n; i ++) cin >> a[i];
	sort ( a + 1, a + n + 1);
	a[n + 1] = 1e18;	
	Build(1, 1, n + 1);
	
	char ch;
	while ( q-- ) {
		cin >> ch;
		if ( ch == 'F') {
			cin >> x >> y;
			swap(x, y);
			l = lowerb(x);
			if ( l + y - 1 >= n) {
				update(1, 1, n + 1, l, n + 1, 1);
			}
			else {
				s = lowerb(find(1, 1, n, l + y - 1));
				update(1, 1, n + 1, l,s - 1, 1);
		//		cout << x << " " << l << " " << s << endl;
				y -= (s - l);
				if ( y < 0) while(1);
		//		cout << y << ">" << endl;
				s = upperb(find(1, 1, n + 1, l + y - 1));
				s --;
			//	cout << s << endl;
				update(1, 1, n + 1, s - y + 1, s, 1);
			}
		}
		else {
			cin >> x >> y;
			cout << upperb(y)- lowerb(x) << endl;
		}
	//	for (j= 1; j <= n; j ++) cout << find(1, 1, n, j) << " ";
	//	cout << endl;
	}
}

Compilation message

grow.cpp: In function 'int main()':
grow.cpp:92:20: warning: unused variable 'j' [-Wunused-variable]
   92 |  ll q, i, x, l, y, j, s;
      |                    ^
# Verdict Execution time Memory Grader output
1 Incorrect 158 ms 10964 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 182 ms 4700 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 179 ms 4860 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 166 ms 6828 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 229 ms 11400 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 180 ms 10844 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 378 ms 11980 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 238 ms 11544 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 329 ms 12452 KB Output isn't correct
2 Halted 0 ms 0 KB -