Pagini recente » Cod sursa (job #746663) | Cod sursa (job #2085354) | Cod sursa (job #294848) | Cod sursa (job #720194) | Cod sursa (job #2741748)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("hotel.in");
ofstream fout("hotel.out");
const int nmax = 100000;
int abc[4 * nmax + 10];
int lungil[4 * nmax + 10];
int lungir[4 * nmax + 10];
int n, p;
void build(int nod, int st, int dr)
{
abc[nod] = lungir[nod] = lungil[nod] = dr - st + 1;
if(st == dr)
return;
int mid = (st + dr)/2;
build(nod * 2, st, mid);
build(nod * 2 + 1, mid + 1, dr);
}
void update(int nod, int st, int dr, int l, int r, bool ok)
{
if(l <= st && dr <= r)
{
int val = (dr - st + 1);
if(ok == 0)
val = 0;
abc[nod] = lungil[nod] = lungir[nod] = val;
}
int mid = (st + dr)/2;
if(abc[nod] == 0)
{
abc[nod * 2] = lungil[nod * 2] = lungir[nod * 2] = 0;
abc[nod * 2 + 1] = lungil[nod * 2 + 1] = lungir[nod * 2 + 1] = 0;
}
else if(abc[nod] == dr - st + 1)
{
abc[nod * 2] = lungil[nod * 2] = lungir[nod * 2] = mid - st + 1;
abc[nod * 2 + 1] = lungil[nod * 2 + 1] = lungir[nod * 2 + 1] = dr - mid;
}
if(l <= mid)
update(nod * 2, st, mid, l, r, ok);
if(mid <= r)
update(nod * 2 + 1, mid + 1, dr, l, r, ok);
lungil[nod] = lungil[nod * 2];
lungir[nod] = lungir[nod * 2 + 1];
if(lungil[nod] == mid - st + 1)
lungil[nod] = lungil[nod] + lungil[nod * 2 + 1];
if(lungir[nod] == dr - mid)
lungir[nod] = lungir[nod] + lungir[nod * 2];
abc[nod] = max(max(abc[nod * 2], abc[nod * 2 + 1]), lungir[nod * 2] + lungir[nod * 2 + 1]);
}
int main()
{
fin>>n>>p;
build(1, 1, n);
while(p--)
{
int c;
fin>>c;
if(c == 3)
fout<< abc[1] << "\n";
else
{
int x, y;
fin>>x>>y;
update(1, 1, n, x, x + y - 1, (c == 2));
}
}
return 0;
}