Pagini recente » Cod sursa (job #1601875) | Cod sursa (job #1215705) | Cod sursa (job #446575) | Cod sursa (job #895846) | Cod sursa (job #1237337)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("hotel.in");
ofstream fout("hotel.out");
#define MAX 100002
struct sebi{
int st, dr, rez;
};
sebi a[4*MAX];
int l, r, val, n;
void update(int nod, int st, int dr)
{
// cout<<nod<<" "<<st<<" "<<dr<<" "<<a[nod].st<<" "<<a[nod].dr<<" "<<a[nod].rez<<"\n";
if(l<=st && dr<=r)
{
if(val==0)
{
a[nod].st=a[nod].dr=a[nod].rez=0;
}
else
{
a[nod].st=a[nod].dr=a[nod].rez=dr-st+1;
}
return;
}
int mij=(st+dr)>>1;
if(a[nod].rez==0)
{
a[2*nod+1].rez=a[2*nod+1].st=a[2*nod+1].dr=0;
}
if(a[nod].rez==dr-st+1)
{
a[2*nod+1].rez=a[2*nod+1].st=a[2*nod+1].dr=dr-(mij+1)+1;
}
if(a[nod].rez==0)
{
a[2*nod].rez=a[2*nod].st=a[2*nod].dr=0;
}
if(a[nod].rez==dr-st+1)
{
a[2*nod].rez=a[2*nod].st=a[2*nod].dr=mij-st+1;
}
if(mij+1<=r)
{
update(2*nod+1, mij+1, dr);
}
if(l<=mij)
{
update(2*nod, st, mij);
}
if(a[2*nod].st==mij-st+1)
a[nod].st=a[2*nod].st+a[2*nod+1].st;
else
a[nod].st=a[2*nod].st;
if(a[2*nod+1].dr==dr-(mij+1)+1)
a[nod].dr=a[2*nod+1].dr+a[2*nod].dr;
else
a[nod].dr=a[2*nod+1].dr;
a[nod].rez=max(a[2*nod].rez, max(a[2*nod+1].rez, a[2*nod].dr+a[2*nod+1].st));
//cout<<nod<<" "<<st<<" "<<dr<<" "<<a[nod].st<<" "<<a[nod].dr<<" "<<a[nod].rez<<"\n";
}
void U(int st, int dr, int v)
{
l=st;
r=dr;
val=v;
//cout<<l<<" "<<r<<" "<<v<<"\n";;
update(1, 1, n);
}
int main()
{
int m, i, t, x, y;
fin>>n>>m;
U(1, n, 1);
// cout<<"\n\n\n\n";
while(m--)
{
fin>>t;
if(t==3)
{
fout<<a[1].rez<<"\n";
}
if(t==1)
{
fin>>x>>y;
U(x, x+y-1, 0);
}
if(t==2)
{
fin>>x>>y;
U(x, x+y-1, 1);
}
}
return 0;
}