Pagini recente » Cod sursa (job #2893712) | Cod sursa (job #2160659) | Cod sursa (job #2922071) | Cod sursa (job #798617) | Cod sursa (job #1289341)
#include <iostream>
#include <fstream>
#define NMax 100005
using namespace std;
ifstream f("hotel.in");
ofstream g("hotel.out");
int x, y;
int n, m, type;
int a[6*NMax], b[6*NMax], c[6*NMax];
inline int maxim (int a, int b) { return (a > b)?a:b; };
void update(int nod, int l, int r, int val) {
if (x <= l && r <= y) {
c[nod] = a[nod] = b[nod] = val * (r - l + 1);
return;
}
int mij = (l+r)/2;
if (c[nod] == 0) {
c[2*nod] = a[2*nod] = b[2*nod] = 0;
c[2*nod+1] = a[2*nod+1] = b[2*nod+1] = 0;
} else if (c[nod] == r - l + 1) {
c[2*nod]=a[2*nod]=b[2*nod]=mij-l+1;
c[2*nod+1]=a[2*nod+1]=b[2*nod+1]=r-mij;
}
/// Updating sons
if (x <= mij)
update(2*nod, l, mij, val);
if (y > mij)
update(2*nod+1, mij+1, r, val);
if (a[2*nod] == mij-l+1)
a[nod] = a[2*nod]+a[2*nod+1];
else
a[nod] = a[2*nod];
if (b[2*nod+1] == r - mij)
b[nod] = b[2*nod] + b[2*nod+1];
else
b[nod] = b[2*nod+1];
c[nod] = maxim(maxim(b[nod], a[nod]), maxim(b[2*nod] + a[2*nod+1], maxim(c[2*nod], c[2*nod+1])));
}
void read() {
f>>n>>m;
x=1;
y=n;
update(1, 1, n, 1);
for (int i=1;i<=m;i++) {
int index, len;
f>>type;
if(type==3)
g<<c[1]<<"\n";
else if(type==1) {
f>>index>>len;
x = index;
y = index + len - 1;
update(1, 1, n, 0);
} else {
f>>index>>len;
x = index;
y = index + len - 1;
update(1, 1, n, 1);
}
}
}
int main() {
read();
f.close(); g.close();
return 0;
}