Submission #1260612

#TimeUsernameProblemLanguageResultExecution timeMemory
1260612PlayVoltzGrowing Trees (BOI11_grow)C++20
100 / 100
231 ms16968 KiB
#include <iostream>
#include <map>
#include <vector>
#include <climits>
#include <stack>
#include <string>
#include <queue>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <cctype>
#include <bitset>
#include <iomanip>
#include <cstring>
#include <numeric>
using namespace std;

#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define fi first
#define se second

struct node{
	int s, e, m, mx, mn, lazy;
	node *l, *r;
	void create(){
		if (l==nullptr){
			l = new node(s, m);
			r = new node(m+1, e);
		}
	}
	void propagate(){
		mx+=lazy;
		mn+=lazy;
		if (s!=e){
			create();
			l->lazy+=lazy;
			r->lazy+=lazy;
		}
		lazy=0;
	}
	node(int S, int E){
		s = S, e = E, m = (s+e)/2;
		mx=mn=lazy=0;
		l=r=nullptr;
	}
	void up(int left, int right, int v){
		propagate();
		if (s==left && e==right)lazy+=v;
		else{
			create();
			if (right<=m)l->up(left, right, v);
			else if (left>m)r->up(left, right, v);
			else l->up(left, m, v), r->up(m+1, right, v);
			r->propagate(), l->propagate();
			mx=max(l->mx, r->mx);
			mn=min(l->mn, r->mn);
		}
	}
	int query(int id){
		propagate();
		if (s==e)return mn;
		create();
		r->propagate(), l->propagate();
		if (id<=m)return l->query(id);
		return r->query(id);
	}
	int low(int lim){
		propagate();
		if (s==e)return (mx>=lim?s:1e12);
		create();
		r->propagate(), l->propagate();
		if (l->mx>=lim)return l->low(lim);
		return r->low(lim);
	}
	int high(int lim){
		propagate();
		if (s==e)return (mn<=lim?s:-1e12);
		create();
		r->propagate(), l->propagate();
		if (r->mn<=lim)return r->high(lim);
		return l->high(lim);
	}
}*st;

int32_t main(){
	int n, q, a, b;
	char c;
	cin>>n>>q;
	vector<int> vect(n);
	st = new node(1, n);
	for (int i=0; i<n; ++i)cin>>vect[i];
	sort(vect.begin(), vect.end());
	for (int i=0; i<n; ++i)st->up(i+1, i+1, vect[i]);
	while (q--){
		cin>>c>>a>>b;
		if (c=='F'){
			int l=st->low(b), r=min(n, l+a-1);
			if (l==1e12)continue;
			st->up(l, r, 1);
			if (r==n)continue;
			int top=st->query(r), next=st->query(r+1);
			if (top<=next)continue;
			int start=st->low(top), end=st->high(top-1);
			if (end==r)continue;
			st->up(r+1, end, 1);
			st->up(start, start+end-r-1, -1);
		}
		else cout<<max(0ll, (st->high(b)-st->low(a)+1))<<"\n";
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...