Pagini recente » Cod sursa (job #1006280) | Cod sursa (job #596445) | Cod sursa (job #738232) | Cod sursa (job #2416627) | Cod sursa (job #1837845)
#include <cstdio>
#include <iostream>
#include <queue>
#include <vector>
#include <fstream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cstring>
#include <map>
#include <iomanip>
#include <unordered_map>
#include <stack>
#include <bitset>
#include <cctype>
#include <unordered_set>
#define MOD 66013
#define pb push_back
#define INF 0x3f3f3f3f
#define INFLL (1LL*INF*INF)
#define ll long long
#define NMAX 400005
using namespace std;
typedef pair<int, int> pii;
ifstream fin("hotel.in");
ofstream fout("hotel.out");
int bestst[NMAX],bestdr[NMAX],best[NMAX],qst,qdr,op;
void makeTree(int nod, int st, int dr) {
best[nod]=bestst[nod]=bestdr[nod]=dr-st+1;
if(st>=dr) return;
int mid=(st+dr)/2,fs=(nod<<1);
makeTree(fs,st,mid);
makeTree(fs+1,mid+1,dr);
}
void updateTree(int nod, int st, int dr) {
if(st>=qst && dr<=qdr) {
best[nod]=bestst[nod]=bestdr[nod]=op*(dr-st+1);
return;
}
if(dr<qst || st>qdr) return;
int mid=(st+dr)/2,fs=(nod<<1);
if(best[nod]==0) {
best[fs]=bestst[fs]=bestdr[fs]=0;
best[fs+1]=bestst[fs+1]=bestdr[fs+1]=0;
}
if(best[nod]==dr-st+1) {
best[fs]=bestst[fs]=bestdr[fs]=mid-st+1;
best[fs+1]=bestst[fs+1]=bestdr[fs+1]=dr-mid;
}
updateTree(fs,st,mid);
updateTree(fs+1,mid+1,dr);
bestst[nod]=bestst[fs];
if(bestst[fs]==mid-st+1) bestst[nod]+=bestst[fs+1];
bestdr[nod]=bestdr[fs+1];
if(bestdr[fs+1]==dr-mid) bestdr[nod]+=bestdr[fs];
best[nod]=max(max(best[fs],best[fs+1]), bestdr[fs]+bestst[fs+1]);
}
int main() {
int n,m;
fin>>n>>m;
makeTree(1,1,n);
while(m--) {
fin>>op;
if(op==3) fout<<best[1]<<'\n';
else {
fin>>qst>>qdr;
qdr+=qst-1;
--op;
updateTree(1,1,n);
}
}
return 0;
}