记录编号 |
334065 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[HAOI 2013]软件安装 |
最终得分 |
100 |
用户昵称 |
_Itachi |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.315 s |
提交时间 |
2016-10-31 18:40:09 |
内存使用 |
3.34 MiB |
显示代码纯文本
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=50005<<2;
int n,m,f[maxn],L[maxn],R[maxn],lz[maxn],s,t,qx;
int Rabit_max(int a,int b){return a>b?a:b;}
#define ls rt<<1
#define rs rt<<1|1
#define Lson rt<<1,l,mid
#define Rson rt<<1|1,mid+1,r
void Rabit_up(int rt,int l,int r){
f[rt]=Rabit_max(f[ls],f[rs]);
if(f[rt]<R[ls]+L[rs])f[rt]=R[ls]+L[rs];
int mid=(l+r)>>1;
if(L[ls]==mid-l+1)L[rt]=L[ls]+L[rs];
else L[rt]=L[ls];
if(R[rs]==r-mid)R[rt]=R[rs]+R[ls];
else R[rt]=R[rs];
}
void Rabit_down(int rt,int l,int r){
if(!lz[rt])return;
int mid=(l+r)>>1;
lz[ls]=lz[rs]=lz[rt];
if(lz[rt]==1)
L[ls]=R[ls]=f[ls]=mid-l+1,
L[rs]=R[rs]=f[rs]=r-mid;
else
L[ls]=R[ls]=f[ls]=0,
L[rs]=R[rs]=f[rs]=0;
lz[rt]=0;
}
void Rabit_set(int rt,int l,int r){
if(l==r){
f[rt]=L[rt]=R[rt]=1;return;
}
int mid=(l+r)>>1;
Rabit_set(Lson),Rabit_set(Rson);
Rabit_up(rt,l,r);
}
int Rabit_get(int rt,int l,int r){
if(f[rt]<qx||l==r)return 0;
if(L[rt]>=qx)return l;
int mid=(l+r)>>1,res;
Rabit_down(rt,l,r);
res=Rabit_get(Lson);if(res)return res;
if(R[ls]+L[rs]>=qx)return mid-R[ls]+1;
return Rabit_get(Rson);
}
void Rabit_dig(int rt,int l,int r){
if(s<=l&&r<=t){
lz[rt]=qx;
if(qx==1)R[rt]=L[rt]=f[rt]=r-l+1;
else R[rt]=L[rt]=f[rt]=0;
return;
}
Rabit_down(rt,l,r);
int mid=(l+r)>>1;
if(s<=mid)Rabit_dig(Lson);
if(t> mid)Rabit_dig(Rson);
Rabit_up(rt,l,r);
}
void Rabit_main(){
scanf("%d%d",&n,&m);int ope;Rabit_set(1,1,n);
while(m--){
scanf("%d",&ope);
if(ope&1){
scanf("%d",&qx),s=Rabit_get(1,1,n),t=s+qx-1;
printf("%d\n",s);
if(s)qx=-1,Rabit_dig(1,1,n);
}
else scanf("%d%d",&s,&t),t=s+t-1,qx=1,Rabit_dig(1,1,n);
}
}
int main(){
#define _Rabit _RABIT
#ifdef _Rabit
freopen("haoi13t4.in","r",stdin);
freopen("haoi13t4.out","w",stdout);
#endif
Rabit_main();
#ifndef _Rabit
getchar(),getchar();
#endif
fclose(stdin);fclose(stdout);
return 0;
}