Cod sursa(job #2358355)

Utilizator greelioGreenio Greely greelio Data 28 februarie 2019 01:34:02
Problema Hotel Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.46 kb
#include<bits/stdc++.h>
#define N 100010
#define L 2*nod
#define R L|1
using namespace std;

struct lol {
    int x,y,mx,lz;
} h[4*N];

int n,p, a[N], l,r,c;

void build(int st, int dr, int nod) {
    if (st==dr) {
        h[nod]={1,1,1,0};
        return;
    }
    int mid=(st+dr)/2;
    build(st, mid, L);
    build(mid+1,dr,R);
    h[nod]={dr-st+1,dr-st+1,dr-st+1,0};
}

void propag(int nod, int x, int st, int dr) {
    if (!h[nod].lz) return;
    if (st!=dr) h[L].lz=h[R].lz=h[nod].lz;
    h[nod]={x,x,x,0};
}

void update(int st, int dr, int nod) {
    if (h[nod].lz)
    propag(nod, (dr-st+1)*(h[nod].lz==2), st, dr);//1 ocupat

    if (st>r || dr<l) return;
    if (l<=st && dr<=r) {
        h[nod].lz=c;
        propag(nod, (dr-st+1)*(c==2), st, dr);
        return;
    }
    int mid=(st+dr)/2;
    update(st, mid, L);
    update(mid+1, dr, R);
    h[nod].x=h[L].x;
    h[nod].y=h[R].y;
    if (h[nod].x==mid-st+1) h[nod].x+=h[R].x;
    if (h[nod].y==dr-(mid+1)+1) h[nod].y+=h[L].y;
    h[nod].mx=max(h[L].mx, h[R].mx);
    h[nod].mx=max(max(h[nod].mx, h[L].y+h[R].x), max(h[nod].x, h[nod].y));
}

int main() {
    ifstream cin("hotel.in");
    ofstream cout("hotel.out");
    cin>>n>>p;
    build(1,n,1);
    while (p--) {
        cin>>c;
        if (c==3) {
            cout<<h[1].mx<<'\n';
        } else {
            cin>>l>>r;
            r=l+r-1;
            update(1,n,1);
        }
    }

    return 0;
}