Submission #935452

# Submission time Handle Problem Language Result Execution time Memory
935452 2024-02-29T06:15:31 Z RadicaI Growing Trees (BOI11_grow) C++17
10 / 100
467 ms 6588 KB
#include <bits/stdc++.h>
#define int long long
#define pi pair<int,int>
#define pb push_back
#define V vector
#define vi V<int>
#define mi map<int,int>
#define MOD 1000000007
#define MOD2 998244353
#define mp make_pair
#define ins insert
#define qi queue<int>
#define pqi priority_queue<int>
#define si set<int>
#define v2i V<vi>
#define v3i V<v2i>
#define v4i V<v3i>
#define v5i V<v4i>
#define INF 1e18
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define print(x) cout << x<<" ";
#define vpi V<pi>
#define Y cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define msi multiset<int>
#define F first
#define S second
#define ld long double
#define RE return;
#define IMP cout<<-1<<endl;return;
using namespace std;

template <typename T>
std::istream& operator>>(std::istream& in, std::vector<T>& vec) {
    for (T& x : vec) {
        in >> x;
    }
    return in;
}

vi arr; vi heights;

void build(int node, int l, int r){
	if(l==r){
		arr[node] = (l==0 ? heights[l] : heights[l]-heights[l-1]);
		return;
	}
	int mid = (l+r)/2;
	build(2*node,l,mid); build(2*node+1, mid+1, r);
	arr[node] = arr[2*node]+arr[2*node+1];
}

void update(int node, int l, int r, int i, int val){
	if(val == sz(heights)) return;
	if(l==r){
		arr[node] += val;
		return;
	}
	int mid = (l+r)/2;
	if(mid<i) update(2*node+1, mid+1, r, i, val);
	else update(2*node, l, mid, i, val);
	arr[node] = arr[2*node]+arr[2*node+1];
}

int query(int node, int l, int r, int tl, int tr){
	if(tl>tr) return 0;
	if(l==tl && r==tr) return arr[node];
	int mid  = (l+r)/2;
	return query(2*node, l, mid, tl, min(mid, tr)) + query(2*node+1, mid+1, r, max(tl, mid+1), tr);
}

int findl(int val){
	int l=0; int r = sz(heights)-1; int best = -1; int rand=0;
	while(l<=r && rand<=2){
		int mid = (l+r+1)/2;
		if(query(1, 0, sz(heights)-1, 0, mid)<=val){
			best = mid;
			l = mid;
		}else r = mid-1;
		if(l==r) rand++;
	}
	return best;
}

signed main(){
	int n,q; cin >> n>>q; heights.resize(n); arr.resize(4*n); cin >> heights; sort(all(heights));
	build(1, 0, n-1);
	while(q--){
		char c; cin >> c;
		if(c=='C'){
			int l,r; cin >>l>>r;
			cout<<findl(r) - findl(l-1)<<endl;
		}else{
			int cnt,h; cin>>cnt>>h;
			int fst = findl(h-1)+1;
			int lst = fst + cnt-1;
			if(fst==n) continue;
			if(fst + cnt>=n){
				update(1, 0, n-1, fst, 1);
				continue;
			}
			int jhxt = query(1, 0, n-1, 0, lst);
			int aft = findl(jhxt); int bef = findl(jhxt-1);
			if(bef>=fst){
				update(1, 0, n-1, fst, 1);
				update(1, 0, n-1, bef+1, -1);
				update(1, 0, n-1, aft+1, -1);
				update(1, 0, n-1, aft - (lst - bef)+1, 1);
			}else{
				update(1, 0, n-1, aft+1,-1);
				update(1, 0, n-1, aft-cnt+1, 1);
			}
		}
	}
}
# Verdict Execution time Memory Grader output
1 Incorrect 205 ms 5080 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 600 KB Output is correct
2 Correct 9 ms 500 KB Output is correct
3 Correct 10 ms 544 KB Output is correct
4 Correct 6 ms 348 KB Output is correct
5 Correct 249 ms 1536 KB Output is correct
6 Incorrect 318 ms 1872 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 277 ms 1876 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 230 ms 2016 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 277 ms 4124 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 352 ms 4364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 304 ms 4744 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 429 ms 5456 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 378 ms 5080 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 467 ms 6588 KB Output is correct