Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:相信很多人都过不了这组数据吧!!!

Posted by 201158080209 at 2013-01-10 20:35:42 on Problem 2528
In Reply To:相信很多人都过不了这组数据吧!!! Posted by:lingyuntan at 2010-10-19 17:01:22
离散化没问题,向我的程序你提供的数据,克的出正确答案,虽然wa,只要正确的利用线段树就可以了,大家可以看我的程序
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=20000;
int p[maxn+10][2],v[maxn*2*3];
int n;
int ql,qr;
struct node2
{
	int num;
	int data;
};
node2 order[maxn*2+10];
bool cmp(node2 a,node2 b)
{
	return a.data<b.data;
}
int update(int node,int l,int r,int x)
{
	int flag;
	if(l>=ql&&r<=qr)
	{
		if(v[node]) return 1;
		else
		{
			v[node]=x;
			return 0;
		}
	}
	else
	{
		int m=l+(r-l)/2;
		if(v[node])
		{
			flag=1;
			return flag;
		}
		if(ql<=m&&qr>m) flag=update(node*2,l,m,x)&update(node*2+1,m+1,r,x);
		else if(ql<=m) flag=update(node*2,l,m,x);
		else flag=update(node*2+1,m+1,r,x);
	}
	return flag;
}
int main()
{
	int c;
	cin>>c;
	while(c--)
	{
		scanf("%d",&n);
		int i,j;
		int a,b;
		for(i=0;i<n;i++)
		{
			scanf("%d%d",&a,&b);
			order[i*2].data=a;order[i*2].num=-(i+1);
			order[i*2+1].data=b;order[i*2+1].num=i+1;
		}
		sort(order,order+2*n,cmp);
		int tem=0,f=0;;
		for(i=0;i<2*n;i++)//离散化
		{
			if(order[i].data!=tem)
			{
				tem=order[i].data;
				f++;
			}
			if(order[i].num<0) p[-order[i].num][0]=f;
			else p[order[i].num][1]=f;
		}		
		memset(v,0,sizeof(v));
		int amount=0;
		for(i=n;i>=1;i--)//从后往前插入		
		{
			ql=p[i][0];qr=p[i][1];
			if(!update(1,1,maxn,i)) amount++;
		}
		printf("%d\n",amount);
	}
	return 0;
}


Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator