Cod sursa(job #1070260)

Utilizator andreiiiiPopa Andrei andreiiii Data 31 decembrie 2013 14:51:51
Problema Hotel Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.13 kb
#include <algorithm>
#include <fstream>

using namespace std;

const int N=200005;

ifstream fin("hotel.in");
ofstream fout("hotel.out");

int x, y;
int a[3*N], b[3*N], c[3*N], d[3*N];

void update(int nod, int l, int r, int val)
{
    if(l==r)
    {
        a[nod]=b[nod]=c[nod]=val;
        return;
    }
    int mij=(l+r)/2;
    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+1]+b[2*nod];
    else b[nod]=b[2*nod+1];
    c[nod]=max(max(b[2*nod]+a[2*nod+1], max(c[2*nod], c[2*nod+1])), max(a[nod], b[nod]));
}

int main()
{
    int n, m, i;
    fin>>n>>m;
    x=1;
    y=n;
    update(1, 1, n, 1);
    while(m--)
    {
        fin>>i;
        if(i==3) fout<<c[1]<<"\n";
        else if(i==1)
        {
            fin>>x>>y;
            y+=x-1;
            update(1, 1, n, 0);
        }
        else
        {
            fin>>x>>y;
            y+=x-1;
            update(1, 1, n, 1);
        }
    }
    fin.close();
    fout.close();
}