Cod sursa(job #2245921)

Utilizator trifangrobertRobert Trifan trifangrobert Data 26 septembrie 2018 10:47:20
Problema A+B Scor 0
Compilator cpp Status done
Runda Lista lui wefgef Marime 2.7 kb
#include <iostream>

#include <algorithm>
#include <fstream>

using namespace std;

struct AINT
{
    int left, right, best;
    bool flag;
    AINT()
    {
        this->left = this->right = this->best = 0;
        this->flag = false;
    }
    AINT(const int &left, const int &right, const int &best, const bool &flag)
   {
       this->left = left;
       this->right = right;
       this->best = best;
       this->flag = flag;
   }
};

const int NMAX = 100010;
int n, p;
AINT aint[4 * NMAX];

inline int LeftSon(const int &x)
{
    return 2 * x;
}

inline int RightSon(const int &x)
{
    return 2 * x + 1;
}

void Build(int node, int left, int right)
{
    if (left == right)
    {
        aint[node] = AINT(1, 1, 1, false);
        return;
    }
    int mid = (left + right) / 2;
    Build(LeftSon(node), left, mid);
    Build(RightSon(node), mid + 1, right);
    aint[node].left = aint[LeftSon(node)].left + aint[RightSon(node)].left;
    aint[node].right = aint[LeftSon(node)].right + aint[RightSon(node)].right;
    aint[node].best = aint[LeftSon(node)].best + aint[RightSon(node)].best;
    aint[node].flag = false;
}

void Update(int node, int left, int right, const int &LeftQuery, const int &RightQuery)
{
    ///vin oameni
    if (LeftQuery <= left && right <= RightQuery)
    {
        aint[node] = AINT(0, 0, 0, true);
        return;
    }
    int mid = (left + right) / 2;
    if (LeftQuery <= mid)
        Update1(LeftSon(node), left, mid, LeftQuery, RightQuery);
    if (RightQuery >= mid + 1)
        Update1(RightSon(node), mid + 1, right, LeftQuery, RightQuery);
}

void Propagate(int node, int left, int right, const int &LeftQuery, const int &RightQuery)
{
    ///pleaca oameni
    if (LeftQuery <= left && right <= RightQuery)
    {
        aint[node] = AINT(0, 0, 0, true);
        return;
    }
    int mid = (left + right) / 2;
    if (LeftQuery <= mid)
        Propagate(LeftSon(node), left, mid, LeftQuery, RightQuery)
    if (RightQuery >= mid + 1)
        Propagate(RightSon(node), mid + 1, right, LeftQuery, RightQuery);
    aint[node].flag = false;
    aubt

}

inline int Query()
{
    return aint[1].best;
}

int main()
{
    ifstream fin("hotel.in");
    ofstream fout("hotel.out");
    fin >> n >> p;
    int st, dr;
    for (int i = 1;i <= p;++i)
    {
        fin >> op;
        if (op == 1)
        {
            fin >> st >> dr;
            Update(1, 1, n, st, dr);
        }
        else if (op == 2)
        {
            fin >> st >> dr;
            Propagate(1, 1, n, st, dr);
        }
        else
            fout << Query() << "\n";
    }
    fin.close();
    fout.close();
    return 0;
}