Pagini recente » Cod sursa (job #2661594) | Cod sursa (job #3214343) | Cod sursa (job #2957485) | Cod sursa (job #2664363) | Cod sursa (job #2958955)
#include <bits/stdc++.h>
#define pb push_back
#define pii pair<int, int>
using ll = long long;
using ci = const int;
using cll = const long long;
using namespace std;
const int NMAX = 1e5 + 5;
/*******************************/
// INPUT / OUTPUT
ifstream f("hotel.in");
ofstream g("hotel.out");
/*******************************/
/// GLOBAL DECLARATIONS
int N, Q;
int lungime[4 * NMAX];
short lazy[4 * NMAX];
struct Node
{
int st, dr, maxx;
} arb[4 * NMAX];
/*******************************/
/// FUNCTIONS
void ReadInput();
void Solution();
void Output();
/*******************************/
///-------------------------------------
inline void ReadInput()
{
f >> N >> Q;
}
///-------------------------------------
void update_lazy(ci &arbSt, ci &arbDr, ci &node)
{
if (lazy[node] == 1)
{
arb[node].st = arbDr - arbSt + 1;
arb[node].dr = arbDr - arbSt + 1;
arb[node].maxx = arbDr - arbSt + 1;
}
else
{
arb[node].st = 0;
arb[node].dr = 0;
arb[node].maxx = 0;
}
if (arbSt != arbDr)
{
lazy[2 * node] = lazy[node];
lazy[2 * node + 1] = lazy[node];
}
lazy[node] = -1;
}
///-------------------------------------
void update(ci &st, ci &dr, ci &arbSt, ci &arbDr, ci &node, ci &val)
{
if (!lungime[node]) lungime[node] = arbDr - arbSt + 1;
if (lazy[node] != -1)
{
update_lazy(arbSt, arbDr, node);
}
if (arbDr < st || arbSt > dr) return;
if (st <= arbSt && arbDr <= dr)
{
lazy[node] = val;
update_lazy(arbSt, arbDr, node);
return;
}
int mid = (arbSt + arbDr) / 2;
update(st, dr, arbSt, mid, 2 * node, val);
update(st, dr, mid + 1, arbDr, 2 * node + 1, val);
arb[node].st = arb[2 * node].st;
if (arb[2 * node].maxx == lungime[2 * node])
arb[node].st = lungime[2 * node] + arb[2 * node + 1].st;
arb[node].dr = arb[2 * node + 1].dr;
if (arb[2 * node + 1].maxx == lungime[2 * node + 1])
arb[node].dr = lungime[2 * node + 1] + arb[2 * node].dr;
arb[node].maxx = max({arb[2 * node].maxx, arb[2 * node + 1].maxx, arb[2 * node].dr + arb[2 * node + 1].st});
}
///------------------------------------
inline void Solution()
{
update(1, N, 1, N, 1, 1);
int tip, st, len;
while (Q --)
{
f >> tip;
if (tip == 1)
{
f >> st >> len;
update(st, st + len - 1, 1, N, 1, 0);
continue;
}
if (tip == 2)
{
f >> st >> len;
update(st, st + len - 1, 1, N, 1, 1);
continue;
}
g << arb[1].maxx << "\n";
}
}
///-------------------------------------
inline void Output()
{
}
///-------------------------------------
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ReadInput();
Solution();
Output();
return 0;
}