25pts求捞
查看原帖
25pts求捞
817681
HZHDCM楼主2024/6/6 20:11

写了很久了,一直不知道哪里错了

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+5;
int n,m,a[N],cnt;
struct Tree{
	int l,r;
	int max,wmax,add,pre;
}t[N<<2];
void push_up(int p){
	t[p].pre=t[p<<1].pre+t[p<<1|1].pre;
	t[p].max=max(t[p<<1].max,t[p<<1|1].max);
	t[p].wmax=max(t[p<<1].wmax,t[p<<1|1].wmax);
}
void build(int l,int r,int p){
	t[p].l=l;t[p].r=r;
	if(l==r){
		t[p].pre=t[p].max=a[l];
		t[p].wmax=0;
		return ;
	}
	int mid=(l+r)>>1;
	build(l,mid,p<<1);
	build(mid+1,r,p<<1|1);
	push_up(p);
}
void push_down(int p){
	if(t[p].add){
		t[p<<1].pre+=(t[p<<1].r-t[p<<1].l+1)*t[p].add;
		t[p<<1|1].pre+=(t[p<<1|1].r-t[p<<1|1].l+1)*t[p].add;
		t[p<<1].max+=t[p].add;
		t[p<<1|1].max+=t[p].add;
		if(t[p<<1].wmax)t[p<<1].wmax+=t[p].add;
		if(t[p<<1|1].wmax)t[p<<1|1].wmax+=t[p].add;
		t[p<<1].add+=t[p].add;t[p<<1|1].add+=t[p].add;
		t[p].add=0;
	}
}
void update(int p,int x,int k){
	if(t[p].l==t[p].r){
		t[p].wmax=t[p].pre=k-t[p].pre;
		t[p].max=0;
		return ;
	}
	push_down(p);
	int mid=(t[p].l+t[p].r)>>1;
	if(x<=mid)update(p<<1,x,k);
	else update(p<<1|1,x,k);
	push_up(p);
}
void upd_add(int p,int x,int y,int k){
	if(x<=t[p].l&&y>=t[p].r){
		t[p].pre+=(t[p].r-t[p].l+1)*k;
		t[p].max+=k;t[p].add+=k;
		if(t[p].wmax)t[p].wmax+=k;
		return ;
	}
	push_down(p);
	int mid=(t[p].l+t[p].r)>>1;
	if(x<=mid)upd_add(p<<1,x,y,k);
	if(y>mid)upd_add(p<<1|1,x,y,k);
	push_up(p);
}
void upd_zro(int p,int x){
	if(t[p].l==t[p].r){
		t[p].pre=t[p].max=t[p].wmax=t[p].add=0;
		return ;
	}
	push_down(p);
	int mid=(t[p].l+t[p].r)>>1;
	if(x<=mid)upd_zro(p<<1,x);
	else upd_zro(p<<1|1,x);
	push_up(p);
}
pair<pair<int,int>,int> query(int p,int x,int y){
	if(x<=t[p].l&&y>=t[p].r){
		if(t[p].l==t[p].r){
			if(t[p].wmax)return make_pair(make_pair(t[p].wmax,t[p].l),1);
			else return make_pair(make_pair(t[p].max,t[p].l),0);
		}
		else{
			push_down(p);
			if(t[p].wmax){
				if(t[p<<1|1].wmax==t[p].wmax)return query(p<<1|1,x,y);
				if(t[p<<1].wmax==t[p].wmax)return query(p<<1,x,y);
			}
			else{
				if(t[p<<1|1].max==t[p].max)return query(p<<1|1,x,y);
				if(t[p<<1].max==t[p].max)return query(p<<1,x,y);
			}
		}
	}
	push_down(p);
	int mid=(t[p].l+t[p].r)>>1;
	pair<pair<int,int>,int> ans=make_pair(make_pair(0,0),0);
	if(y>mid){
		pair<pair<int,int>,int> pos=query(p<<1|1,x,y);
		if((pos.second&&!ans.second)||(ans.second&&pos.second&&pos.first.first>ans.first.first)){
			ans=pos;
		}
		else if(pos.first.first>ans.first.first){
			ans=pos;
		}
	}
	if(x<=mid){
		pair<pair<int,int>,int> pos=query(p<<1,x,y);
		if((pos.second&&!ans.second)||(ans.second&&pos.second&&pos.first.first>ans.first.first)){
			ans=pos;
		}
		else if(pos.first.first>ans.first.first){
			ans=pos;
		}
	}
	return ans;
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>a[i];
	build(1,n,1);
	while(m--){
		int opt,a,b;
		cin>>opt>>a>>b;
		if(opt==1){
			update(1,a,b);
		}
		if(opt==2){
			pair<pair<int,int>,int> k=query(1,a,b);
			int whe=k.first.second,val=k.first.first;
			cout<<val<<endl;
			cnt+=val;
			upd_zro(1,whe);
		}
		if(opt==3){
			int k;
			cin>>k;
			upd_add(1,a,b,k);
		}
	}
	if(cnt<10000)cout<<"QAQ\n";
	else if(cnt<10000000)cout<<"Sakura\n";
	else cout<<"ice\n";
	return 0;
}
2024/6/6 20:11
加载中...