Submission #743975

# Submission time Handle Problem Language Result Execution time Memory
743975 2023-05-18T06:52:51 Z jamezzz Weirdtree (RMI21_weirdtree) C++17
13 / 100
607 ms 64020 KB
#include "weirdtree.h"
#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
#define dbg(...) printf(__VA_ARGS__);
#else
#define dbg(...)
#endif
#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define INF 1023456789
typedef long long ll;
typedef pair<int,int> ii;

#define maxn 300005

int n,q,h[maxn],k1=true,l1rn=true;
set<ii> s;
ll tot;

struct node{
	int s,e,m;ll v;ii mx;
	node *l,*r;
	node(int _s,int _e){
		s=_s,e=_e,m=(s+e)>>1,v=0,mx={0,-s};
		if(s!=e)l=new node(s,m),r=new node(m+1,e);
	}
	void up(int x,ll nv){
		if(s==x&&e==x){
			v=nv;
			mx={(int)nv,-s};
			return;
		}
		if(x<=m)l->up(x,nv);
		else r->up(x,nv);
		v=l->v+r->v;
		mx=max(l->mx,r->mx);
	}
	ii qmx(int x,int y){
		if(s==x&&e==y)return mx;
		if(y<=m)return l->qmx(x,y);
		else if(x>m)return r->qmx(x,y);
		else return max(l->qmx(x,m),r->qmx(m+1,y));
	}
	ll qry(int x,int y){
		if(s==x&&e==y)return v;
		if(y<=m)return l->qry(x,y);
		else if(x>m)return r->qry(x,y);
		else return l->qry(x,m)+r->qry(m+1,y);
	}
}*rt;

void initialise(int N,int Q,int H[]){
	n=N,q=Q;
	for(int i=1;i<=n;++i)h[i]=H[i];
	
	rt=new node(1,n);
	for(int i=1;i<=n;++i)rt->up(i,h[i]);
	
	s.insert({0,1});
	for(int i=1;i<=n;++i)s.insert({h[i],1}),tot+=h[i];
}
void cut(int l,int r,int k){
	if(n<=1000&&q<=1000){
		vector<int> v;
		for(int i=l;i<=r;++i)v.pb(h[i]);
		v.pb(0);
		sort(all(v));
		int num=0,mn=v.back(),rem=k;
		while(!v.empty()){
			int x=v.back();
			if((ll)num*(mn-x)<=rem){
				rem-=num*(mn-x);
				++num;
				mn=x;
				v.pop_back();
			}
			else{
				int sub=rem/num;
				mn-=sub;
				rem-=sub*num;
				break;
			}
		}
		int cnt=0;
		for(int i=l;i<=r;++i){
			if(h[i]>=mn){
				if(cnt<rem)h[i]=mn-1;
				else h[i]=mn;
				++cnt;
			}
			h[i]=max(h[i],0);
		}
		return;
	}
	
	if(l1rn&&l==1&&r==n){
		
	}
	else l1rn=false;
	
	if(k1&&k==1){
		auto[h,i]=rt->qmx(l,r);
		i=-i;
		rt->up(i,h-1);
	}
	else k1=false;
}
void magic(int i,int x){
	if(n<=1000&&q<=1000){
		h[i]=x;
	}
	if(l1rn){
		
	}
	if(k1){
		rt->up(i,x);
	}
}
ll inspect(int l,int r){
	if(n<=1000&&q<=1000){
		ll ans=0;
		for(int i=l;i<=r;++i)ans+=h[i];
		return ans;
	}
	else if(l1rn){
		
	}
	else if(k1){
		return rt->qry(l,r);
	}
	return -1;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 468 KB Output is correct
2 Correct 7 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 468 KB Output is correct
2 Correct 7 ms 468 KB Output is correct
3 Correct 88 ms 14460 KB Output is correct
4 Incorrect 112 ms 16028 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 528 KB Output is correct
2 Correct 3 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 528 KB Output is correct
2 Correct 3 ms 468 KB Output is correct
3 Correct 568 ms 53452 KB Output is correct
4 Correct 567 ms 64020 KB Output is correct
5 Incorrect 607 ms 60076 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 334 ms 51232 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 468 KB Output is correct
2 Correct 7 ms 468 KB Output is correct
3 Correct 88 ms 14460 KB Output is correct
4 Incorrect 112 ms 16028 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 468 KB Output is correct
2 Correct 7 ms 468 KB Output is correct
3 Correct 88 ms 14460 KB Output is correct
4 Incorrect 112 ms 16028 KB Output isn't correct
5 Halted 0 ms 0 KB -