Pagini recente » Cod sursa (job #79722) | Cod sursa (job #2235815) | Cod sursa (job #2047811) | Cod sursa (job #943200) | Cod sursa (job #1413738)
#include <fstream>
using namespace std;
ifstream f("hotel.in");
ofstream g("hotel.out");
int n , q, tip , _1 , _2;
#define amax 400005
int a[amax],l[amax],r[amax];
void build(int x,int s,int d){
if( s == d ){
a[x] = l[x] = r[x] = 1;
return ;
}
int m = (s+d)>>1;
build( x*2 , s , m );
build( x*2+1, m+1, d );
a[x]=l[x]=r[x] = a[x*2] + a[x*2+1];
}
void update(int x,int s,int d){
if( _1 <= s && d <= _2){
if( tip == 2 )
a[x] = l[x] = r[x] = d-s+1;
else
a[x] = l[x] = r[x] = 0;
return ;
}
int m = (s+d)>>1;
if( a[x] == 0 ){
a[x*2] = l[x*2] = r[x*2] = 0;
a[x*2+1] = l[x*2+1] = r[x*2+1] = 0;
}
if( a[x] == d-s+1 ){
a[x*2] = l[x*2] = r[x*2] = m-s+1;
a[x*2+1] = l[x*2+1] = r[x*2+1] = d-m;
}
if( _1 <= m ) update( x*2 , s , m );
if( m < _2 ) update( x*2+1, m+1 , d );
if( l[x*2] == m-s+1 )
l[x] = l[x*2] + l[x*2+1];
else
l[x] = l[x*2];
if( r[x*2+1] == d-m )
r[x] = r[x*2+1] + r[x*2];
else
r[x] = r[x*2+1];
a[x] = max( max(a[x*2] , a[x*2+1]) , r[x*2] + l[x*2+1] );
}
int main()
{
f >> n >> q;
build(1,1,n);
for( int i=1; i<=q; ++i){
f >> tip;
if( tip == 3 ){
g << a[1] << '\n';
}else{
f >> _1 >> _2;
_2 = _1 + _2 - 1;
update(1,1,n);
}
}
return 0;
}