Submission #697134

# Submission time Handle Problem Language Result Execution time Memory
697134 2023-02-08T14:22:39 Z dsyz Growing Trees (BOI11_grow) C++17
0 / 100
76 ms 33188 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MAXN (1000005)
struct node{
	ll s, e, m, val, maxi, lazy;
	node *l, *r;
	node(ll S, ll E){
		s = S, e = E, m = (s+e)/2;
		val = 0;
		maxi = 0;
		lazy = 0;
		if(s != e){
			l = new node(s,m);
			r = new node(m + 1,e);
		}
	}
	void propogate(){
		if(lazy==0) return;
		val += lazy*(e-s+1);
		maxi += lazy;
		if(s != e){ //not a leaf, send lazy tags to children (remember to write this if statement)
			l->lazy += lazy;
			r->lazy += lazy;
		}
		lazy = 0;
	}
	void update(int S, int E, ll V){
		if(s == S && e == E) lazy += V;
		else{
			if(E <= m) l->update(S, E, V);
			else if (m < S) r->update(S, E, V);
			else l->update(S, m, V),r->update(m+1, E, V);
			l->propogate(),r->propogate();
			val = l->val + r->val;
			maxi = max(l -> maxi,r -> maxi);
		}
	}
	ll bsL(ll H){ //leftmost position >= H
		propogate(); //remember to propogate
		if(s == e){
			if(maxi >= H) return s;
			else return 1000000005;
		}
		if(l -> maxi >= H){
			return l -> bsL(H);
		}else if(r -> maxi >= H){
			return r -> bsL(H);
		}else{
			return 1000000005;
		}
	}
	ll query(int S, int E){
		propogate(); //remember to propogate
		if(s == S && e == E) return val; 
		else if(E <= m) return l->query(S, E); 
		else if(S >= m+1) return r->query(S, E);
		else return l->query(S, m) + r->query(m+1, E); 
	}
} *root;

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);
	ll N,M;
	cin>>N>>M;
	root = new node(0,N - 1);
	ll arr[N];
	for(ll i = 0;i < N;i++){
		cin>>arr[i];
	}
	sort(arr,arr + N);
	for(ll i = 0;i < N;i++){
		root -> update(i,i,arr[i]);
	}
	for(ll i = 0;i < M;i++){
		char t;
		cin>>t;
		if(t == 'F'){
			ll c,h;
			cin>>c>>h;
			ll start = root -> bsL(h);
			if(start == 1000000005){
				continue;
			}
			ll endval = root -> query(min(N - 1,start + c - 1),min(N - 1,start + c - 1));
			ll end = -1e18;
			end = root -> bsL(endval);
			end--;
			ll end2 = root -> bsL(endval + 1);
			if(end2 == 1000000005){
				end2 = N - 1;
			}else{
				end2--;
			}
			ll start2 = max(end + 1,end2 - (c - (end - start + 1)) + 1);
			if(start2 == 1000000005){
				continue;
			}
			if(start <= end) root -> update(start,end,1);
			if(start2 <= end2) root -> update(start2,end2,1);
		}else if(t == 'C'){
			ll L,R;
			cin>>L>>R;
			ll start = root -> bsL(L);
			ll end = root -> bsL(R + 1);
			if(end == 1000000005){
				end = N - 1;
			}else{
				end--;
			}
			if(start == 1000000005 || end == 1000000005){
				cout<<0<<'\n';
			}else{
				cout<<end - start + 1<<'\n';
			}
		}
	}
}
# Verdict Execution time Memory Grader output
1 Runtime error 44 ms 29656 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 2772 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 2644 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 34 ms 21992 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 35 ms 25284 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 45 ms 27000 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 45 ms 29020 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 39 ms 28748 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 76 ms 33188 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -