Pagini recente » Cod sursa (job #2923648) | Cod sursa (job #2652595) | Cod sursa (job #263983) | Cod sursa (job #2769435) | Cod sursa (job #1338348)
#include <fstream>
#define DIM 100001
using namespace std;
int maxim(int a, int b)
{
if(a>b)
return a;
else return b;
}
struct elem
{
int secv_left, secv_right, tot, secv;
};
elem arb[4*DIM+66];
void build(int l, int r, int nod)
{
int mij=(l+r)/2;
arb[nod].secv=r-l+1;
arb[nod].secv_right=r-l+1;
arb[nod].secv_left=r-l+1;
arb[nod].tot=r-l+1;
if(l!=r)
{
build(l, mij, 2*nod);
build(mij+1, r, 2*nod+1);
}
}
int a1, a2, p, n, tip, i, m;
void umple(int l, int r, int nod)
{
int mij=(l+r)/2;
if(a1<=l&&r<=a2)
{
arb[nod].secv=0; arb[nod].secv_left=0; arb[nod].secv_right=0; arb[nod].tot=-(r-l+1);
}
else
{
if(arb[nod].secv==(r-l+1))
{
arb[nod].secv=r-l+1;
arb[nod].secv_right=r-l+1;
arb[nod].secv_left=r-l+1;
arb[nod].tot=r-l+1;
}
if(arb[nod].secv==0)
{
arb[nod].secv=0;
arb[nod].secv_right=0;
arb[nod].secv_left=0;
arb[nod].tot=0;
}
if(a1<=mij)
umple(l, mij, 2*nod);
if(a2>mij)
umple(mij+1, r, 2*nod+1);
arb[nod].secv=maxim(maxim(arb[2*nod].secv, arb[2*nod+1].secv), arb[2*nod].secv_right+arb[2*nod+1].secv_left);
if(arb[2*nod].tot>0)
arb[nod].secv_left=arb[2*nod].tot+arb[2*nod+1].secv_left;
else
arb[nod].secv_left=arb[2*nod].secv_left;
if(arb[2*nod+1].tot>0)
arb[nod].secv_right=arb[2*nod+1].tot+arb[2*nod].secv_right;
else
arb[nod].secv_right=arb[2*nod+1].secv_right;
if(arb[nod].secv==(r-l+1))
{
arb[nod].tot=(r-l+1);
}
else
arb[nod].tot=-(r-l+1);
}
}
void gol(int l, int r, int nod)
{
int mij=(l+r)/2;
if(a1<=l&&r<=a2)
{
arb[nod].secv=r-l+1; arb[nod].secv_left=r-l+1; arb[nod].secv_right=r-l+1; arb[nod].tot=r-l+1;
}
else
{
if(arb[nod].secv==(r-l+1))
{
arb[2*nod].secv=r-l+1;
arb[2*nod].secv_right=r-l+1;
arb[2*nod].secv_left=r-l+1;
arb[2*nod].tot=r-l+1;
arb[2*nod+1].secv=r-l+1;
arb[2*nod+1].secv_right=r-l+1;
arb[2*nod+1].secv_left=r-l+1;
arb[2*nod+1].tot=r-l+1;
}
if(arb[nod].secv==0)
{
arb[2*nod].secv=0;
arb[2*nod].secv_right=0;
arb[2*nod].secv_left=0;
arb[2*nod].tot=0;
arb[2*nod+1].secv=0;
arb[2*nod+1].secv_right=0;
arb[2*nod+1].secv_left=0;
arb[2*nod+1].tot=0;
}
if(a1<=mij)
gol(l, mij, 2*nod);
if(a2>mij)
gol(mij+1, r, 2*nod+1);
arb[nod].secv=maxim(maxim(arb[2*nod].secv, arb[2*nod+1].secv), arb[2*nod].secv_right+arb[2*nod+1].secv_left);
if(arb[2*nod].tot>0)
arb[nod].secv_left=arb[2*nod].tot+arb[2*nod+1].secv_left;
else
arb[nod].secv_left=arb[2*nod].secv_left;
if(arb[2*nod+1].tot>0)
arb[nod].secv_right=arb[2*nod+1].tot+arb[2*nod].secv_right;
else
arb[nod].secv_right=arb[2*nod+1].secv_right;
if(arb[nod].secv==(r-l+1))
{
arb[nod].tot=(r-l+1);
}
else
arb[nod].tot=-(r-l+1);
}
}
int main()
{
ifstream in ("hotel.in");
ofstream out("hotel.out");
in>>n>>p;
build(1, n, 1);
while(p--)
{
in>>tip;
if(tip==1)
{
in>>i>>m;
a1=i; a2=i+m-1;
umple(1, n, 1);
}
if(tip==2)
{
in>>i>>m;
a1=i; a2=i+m-1;
gol(1, n, 1);
}
if(tip==3)
out<<arb[1].secv<<"\n";
}
in.close();
out.close();
return 0;
}