Cod sursa(job #2281786)

Utilizator DimaTCDima Trubca DimaTC Data 12 noiembrie 2018 18:49:28
Problema Hotel Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.44 kb
#include<bits/stdc++.h>
#define N 600110
#define L 2*nod
#define R L|1
using namespace std;

struct lol {
    int st, dr, mx, val;
} h[N];

int n,m, st,dr, c, val;

void lz(int st,int dr, int nod){
    if(h[nod].val){
        if(h[nod].val==1) h[L].val=h[R].val=1, h[nod]={0,0,0,0};
        else h[L].val=h[R].val=2, h[nod]={dr-st+1, dr-st+1, dr-st+1, 0};
    }
}
void build(int st,int dr, int nod){
    if(st==dr){
        h[nod].st=h[nod].dr=h[nod].mx=1;
        return;
    }
    int mij=(st+dr)>>1;
    build(st,mij, L); build(mij+1,dr, R);
    h[nod].st=h[nod].dr=h[nod].mx=dr-st+1;
}
void update(int st,int dr, int nod, int l,int r,int c){
    if(l<=st&&r>=dr){
        h[nod].val=c;
        lz(st,dr, nod);
        return;
    }
    int mij=(st+dr)>>1;
    lz(st,mij, L); lz(mij+1,dr, R);
    if(l<=mij) update(st,mij, L, l,r,c);
    if(r>mij) update(mij+1,dr, R, l,r,c);
    h[nod].mx=max(h[L].mx, max(h[L].dr+h[R].st, h[R].mx));
    h[nod].st=h[L].st;
    if(h[nod].st==mij-st+1) h[nod].st+=h[R].st;
    h[nod].dr=h[R].dr;
    if(h[nod].dr==dr-mij) h[nod].dr+=h[L].dr;
}
int main () {
    ifstream cin("hotel.in");
    ofstream cout("hotel.out");
    cin>>n>>m;
    build(1,n,1);

    while (m--) {
        cin>>c;
        if(c<=2){
            cin>>st>>val;
            dr=st+val-1;
            lz(1,1,n);
            update(1,n, 1,st,dr,c);
        } else cout<<h[1].mx<<"\n";
    }
    return 0;
}