社区讨论
100分求调!玄关!!!QWQ
P2894[USACO08FEB] Hotel G参与者 3已保存回复 7
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 7 条
- 当前快照
- 1 份
- 快照标识符
- @mlqs2wq7
- 此快照首次捕获于
- 2026/02/17 23:48 前天
- 此快照最后确认于
- 2026/02/18 22:20 14 小时前
求求了,调了好久了真没发现啥问题啊......
WA on Subtask #1 #1
QvQ求dalao调
CPP#include<bits/stdc++.h>
using namespace std;
const int N=5e4+5;
int n,m,op,x,y;
struct{
int l,r,lmax,rmax,ans,lazy;
#define mid (t[p].l+t[p].r)/2
}t[N<<2];
void update(int p){
t[p].ans=max(max(t[p<<1].ans,t[p<<1|1].ans),t[p<<1].rmax+t[p<<1|1].lmax);
t[p].lmax=t[p<<1].lmax==t[p<<1].r-t[p<<1].l+1?t[p<<1].r-t[p<<1].l+1+t[p<<1|1].lmax:t[p<<1].lmax;
t[p].rmax=t[p<<1|1].rmax==t[p<<1|1].r-t[p<<1|1].l+1?t[p<<1|1].r-t[p<<1|1].l+1+t[p<<1].rmax:t[p<<1|1].rmax;
}
void build(int p,int lc,int rc){
t[p].l=lc;
t[p].r=rc;
t[p].lazy=-1;
if(lc==rc){
t[p].ans=t[p].lmax=t[p].rmax=1;
return;
}
build(p<<1,lc,(lc+rc)/2);
build(p<<1|1,(lc+rc)/2+1,rc);
update(p);
}
void spread(int p){
if(t[p].lazy!=-1){
if(t[p].lazy==0){
t[p<<1].lmax=t[p<<1].rmax=t[p<<1].ans=t[p<<1].r-t[p<<1].l+1;
t[p<<1|1].lmax=t[p<<1|1].rmax=t[p<<1|1].ans=t[p<<1|1].r-t[p<<1|1].l+1;
}
else{
t[p<<1].lmax=t[p<<1].rmax=t[p<<1].ans=0;
t[p<<1|1].lmax=t[p<<1|1].rmax=t[p<<1|1].ans=0;
}
t[p<<1].lazy=t[p<<1|1].lazy=t[p].lazy;
t[p].lazy=-1;
}
}
void change0(int p,int ax,int bx){//[ax,ax+bx-1]->0
if(ax<=t[p].l && t[p].r<ax+bx){
t[p].lmax=t[p].rmax=t[p].ans=t[p].r-t[p].l+1;
t[p].lazy=0;
return;
}
spread(p);
if(mid>=ax)
change0(p<<1,ax,bx);
if(mid<ax+bx-1)
change0(p<<1|1,ax,bx);
update(p);
}
void change1(int p,int ax,int bx){
if(ax<=t[p].l && t[p].r<=bx){
t[p].lmax=t[p].rmax=t[p].ans=0;
t[p].lazy=1;
return;
}
spread(p);
if(mid>=ax)
change1(p<<1,ax,bx);
if(mid<bx)
change1(p<<1|1,ax,bx);
update(p);
}
int ask(int p,int d){
if(t[p].ans<d)
return 0;
spread(p);
if(t[p<<1].ans>=d)
return ask(p<<1,d);
else if(t[p<<1].rmax+t[p<<1|1].lmax>=d){
int al=mid-t[p<<1].rmax+1;
change1(1,mid-t[p<<1].rmax+1,mid-t[p<<1].rmax+d);
return al;//[mid-t[p<<1].rmax+1,mid-t[p<<1].rmax+d]->1
}
else
return ask(p<<1|1,d);
}
signed main(){
cin>>n>>m;
build(1,1,n);
while(cin>>op>>x){
if(op==1)
cout<<ask(1,x)<<endl;
else{
cin>>y;
change0(1,x,y);
}
}
return 0;
}
回复
共 7 条回复,欢迎继续交流。
正在加载回复...