Pagini recente » Cod sursa (job #58356) | Cod sursa (job #2517688) | Cod sursa (job #1509837) | Cod sursa (job #2601916) | Cod sursa (job #1868809)
#include <iostream>
#include <fstream>
#include <bitset>
#define N 100000
using namespace std;
ifstream in("hotel.in");
ofstream out("hotel.out");
bitset<N*2+5> h;
int n, p;
struct Node{int mxl, mxr, mxc;}sgt[N*2+5];
void update(int l, int r, int ul, int ur, int node){
if(l==r){
sgt[node].mxl=(!h[l]?1:0);
sgt[node].mxr=(!h[l]?1:0);
sgt[node].mxc=(!h[l]?1:0);
return;
}
int m=(l+r)/2;
if(ul<=m)update(l, m, ul, ur, node*2);
if(ur>m)update(m+1, r, ul, ur, node*2+1);
sgt[node].mxc=max(max(sgt[node*2].mxc, sgt[node*2+1].mxc),
((sgt[node*2].mxr>0&&sgt[node*2+1].mxl>0)?
sgt[node*2].mxr+sgt[node*2+1].mxl:-1));
sgt[node].mxl=sgt[node*2].mxl;
sgt[node].mxr=sgt[node*2+1].mxr;
if(sgt[node*2].mxr>0&&sgt[node*2+1].mxl>0){
if(sgt[node*2].mxl==sgt[node*2].mxr){
sgt[node].mxl=sgt[node*2].mxr+sgt[node*2+1].mxl;
}
if(sgt[node*2+1].mxl==sgt[node*2+1].mxr){
sgt[node].mxr=sgt[node*2].mxr+sgt[node*2+1].mxl;
}
}
}
int main(){
in>>n>>p;
int x, y, z;
update(1, n, 1, n, 1);
for(int i=1; i<=p; i++){
in>>x;
if(x==1){
in>>y>>z;
for(int j=y; j<y+z; j++)h[j]=1;
update(1, n, y, y+z-1, 1);
}else if(x==2){
in>>y>>z;
for(int j=y; j<y+z; j++)h[j]=0;
update(1, n, y, y+z-1, 1);
}else{
out<<max(max(sgt[1].mxl, sgt[1].mxr), sgt[1].mxc)<<"\n";
}
}
return 0;
}