Pagini recente » Cod sursa (job #3281004) | Cod sursa (job #1452157) | Cod sursa (job #847200) | Cod sursa (job #696326) | Cod sursa (job #841712)
Cod sursa(job #841712)
#include <fstream>
#define Left 2*(Node)
#define Right 2*(Node)+1
#define NM 100010
using namespace std;
ifstream f("hotel.in");
ofstream g("hotel.out");
int N,M;
int O;
int i,j;
int L,R,V;
struct Interval
{
int SendInfo;
int LeftBest,RightBest,Best;
Interval ()
{
SendInfo=-1;
LeftBest=RightBest=Best=0;
}
} AI[4*NM];
void Set (int Node, int V)
{
AI[Node].SendInfo=(V==0);
AI[Node].Best=AI[Node].LeftBest=AI[Node].RightBest=V;
}
void Update (int Node, int S, int D)
{
if (L<=S && D<=R)
{
AI[Node].SendInfo=V;
Set(Node,(D-S+1)*(1-V));
return;
}
int M=(S+D)/2;
if (AI[Node].SendInfo>=0)
{
Set(Left,(M-S+1)*(1-AI[Node].SendInfo));
Set(Right,(D-M)*(1-AI[Node].SendInfo));
AI[Node].SendInfo=-1;
}
if (L<=M)
Update(Left,S,M);
if (R>M)
Update(Right,M+1,D);
AI[Node].LeftBest=AI[Left].LeftBest;
if (AI[Left].LeftBest==M-S+1)
AI[Node].LeftBest+=AI[Right].LeftBest;
AI[Node].RightBest=AI[Right].RightBest;
if (AI[Right].RightBest==D-M)
AI[Node].RightBest+=AI[Left].RightBest;
AI[Node].Best=max(AI[Left].Best,AI[Right].Best);
AI[Node].Best=max(AI[Node].Best,AI[Left].RightBest+AI[Right].LeftBest);
return;
}
int main ()
{
f >> N >> M;
L=1;
R=N;
V=0;
Update(1,1,N);
for (i=1; i<=M; i++)
{
f >> O;
if (O<=2)
{
f >> L >> R;
R=L+R-1;
V=2-O;
Update(1,1,N);
}
if (O==3)
g << AI[1].Best << '\n';
}
f.close();
g.close();
return 0;
}