记录编号 404088 评测结果 AAAAAAAAAAAAAA
题目名称 265.线段覆盖 最终得分 100
用户昵称 Fisher. 是否通过 通过
代码语言 C++ 运行时间 0.940 s
提交时间 2017-05-12 19:37:17 内存使用 15.57 MiB
显示代码纯文本
#include <iostream>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <time.h>
#include <map>
#include <deque>
using namespace std;//不下传式lazy似乎更好用!学一波去!
//-----------------
inline int in()
{
	char c=getchar();
	int x=0,f=1;
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	for(;c>='0'&&c<='9';c=getchar())x=x*10+c-'0';
	return x*f;
}
//-----------------
struct d
{
	int len,s,zr,yr;
	int lazy;
};
d node[800010];
int n,m;
inline void re(int o,int l,int r)
{
	if(node[o].lazy>0)
	{
		node[o].zr=node[o].yr=node[o].s=1;
		node[o].len=r-l+1;
	}
	else
	{
		node[o].len=node[o*2].len+node[o*2+1].len;
		node[o].zr=node[o*2].zr;
		node[o].yr=node[o*2+1].yr;
		if(node[o*2].yr==1&&node[o*2+1].zr==1) node[o].s=node[o*2].s+node[o*2+1].s-1;
		else node[o].s=node[o*2].s+node[o*2+1].s;
	}
}
inline void add(int o,int l,int r,int nl,int nr,int w)
{
	if(l>=nl&&r<=nr)
	{
		node[o].lazy+=w;
		if(l==r)
		{
			node[o].zr=node[o].yr=node[o].s=node[o].len=node[o].lazy>0?1:0;
		}
		else
			re(o,l,r);
		return ;
	}
	int m=(l+r)/2;
	if(m>=nl)
	{
		add(o*2,l,m,nl,nr,w);
	}
	if(m<nr)
	{
		add(o*2+1,m+1,r,nl,nr,w);
	}
	re(o,l,r);
}

int main()
{
	freopen("xdfg.in","r",stdin);
	freopen("xdfg.out","w",stdout);
	ios::sync_with_stdio(false);
	scanf("%d%d",&n,&m);
	while(m--)
	{
		int c,x,y;
		scanf("%d%d%d",&c,&x,&y);
		if(c==1)
		{
			add(1,1,n,x,x+y-1,1);
			printf("%d %d\n",node[1].s,node[1].len);
		}
		else
		{
			add(1,1,n,x,x+y-1,-1);
			printf("%d %d\n",node[1].s,node[1].len);
		}
	}
	return 0;
}