Pagini recente » Cod sursa (job #1170903) | Cod sursa (job #3266035) | Cod sursa (job #87346) | Cod sursa (job #2244986) | Cod sursa (job #1385581)
#include <iostream>
#include <fstream>
using namespace std;
struct Tree{
int bl,br,b;
} t[400000];
int N,P,lazy[400000],c,ql,qr;
void un_lazy(int nod,int l,int r){
if (!lazy[nod]) return;
if (lazy[nod]==1)
t[nod].bl=t[nod].br=t[nod].b=0;
else
t[nod].bl=t[nod].br=t[nod].b=r-l+1;
if (l!=r) lazy[nod*2]=lazy[nod*2+1]=lazy[nod];
lazy[nod]=0;
}
void update(int nod, int l, int r){
un_lazy(nod,l,r);
if (ql<=l && r<=qr){
lazy[nod]=c;
un_lazy(nod,l,r);
return;
}
int mid=(l+r)/2;
if (ql<=mid) update(nod*2,l,mid);
if (qr>mid) update(nod*2+1,mid+1,r);
un_lazy(nod*2,l,mid);
un_lazy(nod*2+1,mid+1,r);
if (t[nod*2].b==mid-l+1) t[nod].bl=t[nod*2].b+t[nod*2+1].bl;
else t[nod].bl=t[nod*2].bl;
if (t[nod*2+1].b==r-mid) t[nod].br=t[nod*2+1].b+t[nod*2].br;
else t[nod].br=t[nod*2+1].br;
t[nod].b=max(max(t[nod*2].b,t[nod*2+1].b),t[nod*2].br+t[nod*2+1].bl);
}
int main(){
ifstream fin("hotel.in");
ofstream fout("hotel.out");
fin >> N >> P;
int i;
c=2,ql=1,qr=N;
update(1,1,N);
for (i=1; i<=P; i++){
fin >> c;
if (c==3) { fout << t[1].b << "\n"; continue; }
fin >> ql >> qr;
qr=ql+qr-1;
update(1,1,N);
}
return 0;
}