Pagini recente » Cod sursa (job #2297420) | Cod sursa (job #642491) | Cod sursa (job #1284636) | Cod sursa (job #858455) | Cod sursa (job #1539146)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("hotel.in");
ofstream fout("hotel.out");
const int LIM = 1e5 + 5;
const int NMax = 4 * LIM;
int Aib[NMax], Left[NMax], Right[NMax];
void BuildTree(int node, int lo, int hi){
if(lo > hi) return;
if(lo == hi){
Aib[node] = Left[node] = Right[node] = 1;
return;
}
int mid = (lo + hi) >> 1;
BuildTree(1, lo, mid);
BuildTree(1, mid + 1, hi);
Aib[node] = Left[node] = Right[node] = hi - lo + 1;
}
void Update(int node, int lo, int hi, int m, int M, bool type){
if(lo > hi || lo > M || hi < m) return;
if(lo >= m & hi <= M){
if(type){
Aib[node] = Left[node] = Right[node] = hi - lo + 1;
} else {
Aib[node] = Left[node] = Right[node] = 0;
}
return;
}
int mid = (lo + hi) >> 1;
if(Aib[node] == 0){
Aib[node * 2] = Left[node * 2] = Right[node * 2] = 0;
Aib[node * 2 + 1] = Left[node * 2 + 1] = Right[node * 2 + 1] = 0;
}
if(Aib[node] == hi - lo + 1){
Aib[node * 2] = Left[node * 2] = Right[node * 2] = mid - lo + 1;
Aib[node * 2 + 1] = Left[node * 2 + 1] = Right[node * 2 + 1] = hi - mid;
}
Update(node * 2, lo, mid, m, M, type);
Update(node * 2 + 1, mid + 1, hi, m, M, type);
Aib[node] = max(Left[node * 2 + 1] + Right[node * 2], max(Aib[node * 2], Aib[node * 2 + 1]));
Left[node] = Left[node * 2];
Right[node] = Right[node * 2 + 1];
if(Left[node] == mid - lo + 1){
Left[node] += Left[node * 2 + 1];
}
if(Right[node] == hi - mid){
Right[node] += Right[node * 2];
}
}
int main(){
int n, p, type, a, b;
fin >> n >> p;
BuildTree(1, 1, n);
for(int i = 1; i <= p; i++){
fin >> type;
if(type == 1){
fin >> a >> b;
Update(1, 1, n, a, a + b - 1, false);
} else {
if(type == 2){
fin >> a >> b;
Update(1, 1, n, a, a + b - 1, true);
} else {
fout << Aib[1] << "\n";
}
}
}
return 0;
}