Pagini recente » Cod sursa (job #652231) | Cod sursa (job #608260) | Cod sursa (job #1940848) | Cod sursa (job #824544) | Cod sursa (job #2465725)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("hotel.in");
ofstream fout("hotel.out");
#define cin fin
#define cout fout
/*
*/
const int NMAX=(2<<19);
int n, m;
struct t
{
int st, dr, maxi;
}arbore[NMAX];
void update(int val, int intLeft, int intRight, int auxLeft, int auxRight, int nod)
{
if(auxLeft==auxRight)
{
arbore[nod]={val,val,val};
return;
}
int mij=(auxLeft+auxRight)/2;
if(intLeft<=mij)
update(val, intLeft, intRight, auxLeft, mij, 2*nod);
if(mij<intRight)
update(val, intLeft, intRight, mij+1, auxRight, 2*nod+1);
arbore[nod].st=arbore[2*nod].st;
if(arbore[2*nod].st==mij-auxLeft+1)
arbore[nod].st+=arbore[2*nod+1].st;
arbore[nod].dr=arbore[2*nod+1].dr;
if(arbore[2*nod+1].dr==auxRight-mij)
arbore[nod].dr+=arbore[2*nod].dr;
arbore[nod].maxi=arbore[2*nod].dr+arbore[2*nod+1].st;
arbore[nod].maxi=max(arbore[nod].maxi, arbore[nod].st);
arbore[nod].maxi=max(arbore[nod].maxi, arbore[nod].dr);
}
int main()
{
int caz, left, right;
cin>>n>>m;
update(1,1,n,1,n,1);
for(int i=1; i<=m; i++)
{
cin>>caz;
if(caz==1)
{
cin>>left>>right;
right=left+right-1;
update(0, left, right, 1, n, 1);
}
else
if(caz==2)
{
cin>>left>>right;
right=left+right-1;
update(1, left, right, 1, n, 1);
}
else
cout<<arbore[1].maxi<<"\n";
}
return 0;
}