zoj 3518 Unsafe Factor

无语了都!!!会升还说我这个暴力!!刚搜题解!!有个用纯模拟过的!!!神呐!!!

我离散化了下 = =。。。没啥好说的。线段树不会。

#include <queue>
#include <stack>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <limits.h>
#include <string.h>
#include <string>
#include <algorithm>

using namespace std;

const int MAX = 10000010;
const int N = 400010;
struct LL{ int x,y,c;};
LL b[N];
int a[N];
bool col[MAX];
bool ans[MAX];
int mmax;
void solve(int n,int cnt,int nn)
{
	for(int i=0; i<n; i++)
	{
		int x = lower_bound(a,a+cnt,b[i].x) - a;
		int y = lower_bound(a,a+cnt,b[i].y) - a;
		for(int k=x; k<y; k++)
		{
			if( col[k] == true )
				col[k] = false;
			else
				col[k] = true;
		}
	}
	for(int i=0; i<cnt-1; i++)
		if( col[i] )
		{
			for(int k=a[i]; k<a[i+1]; k++)
				ans[k] = true;
		}
	int sum = 0;
	mmax = 0;
	for(int i=0; i<nn+1; i++)
		if( ans[i] )
			sum++;
		else
		{
			if( sum > mmax ) mmax = sum;
			sum = 0;
		}
	if( sum > mmax ) mmax = sum;
}

int main()
{
	int n,cnt,n1,n2;
	
	while( ~scanf("%d",&n) )
	{
		memset(ans,false,sizeof(ans));
		memset(col,false,sizeof(col));
		cnt = 0;
		scanf("%d%d",&n1,&n2);
		for(int i=0; i<n1+n2; i++)
		{
			scanf("%d%d",&b[i].x,&b[i].y);
			b[i].y++;
			a[cnt++] = b[i].x; a[cnt++] = b[i].y;
		}
		sort(a,a+cnt);
		cnt = unique(a,a+cnt) - a;
		solve(n1+n2,cnt,n);
		if( mmax == 0 )
			printf("0\n");
		else
			printf("%d\n",mmax);
	}
return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值