离散化,下载的数据太大,求hack数据,,30分
查看原帖
离散化,下载的数据太大,求hack数据,,30分
567642
waioi_lin楼主2022/10/1 23:34
#include "cstdio"
#include "algorithm"
#include "cmath"
#include "iostream"
#include "cstring"
#include "string"
#include "iomanip"
#include "vector"
#include "stack"
#include "map"
#include "set"
#define ll long long
#define retrun return
#define ull unsigned long long
#define itn int
using namespace std;

int in(){
	char c=getchar();
	int x=0,f=1;
	for(;c<'0' || c>'9';c=getchar())
		if(c=='-') f=-1;
	for(;c>='0' && c<='9';c=getchar())
		x=(x<<1)+(x<<3)+(c^48);
	return x*f;
}

struct node
{
	int num, id;
}a[40005];

bool cmp(node x, node y)
{
	if(x.num==y.num)
		return x.id<y.id;
	else
		return x.num<y.num;
}

int main(void){
//	freopen("huo.in","r",stdin);
//	freopen("huo.out","w",stdout);
	int n=in(), tot=0;
	for(int i=1;i<=n;i++)
	{
		a[++tot].num=in();
		a[tot].id=0;
		a[++tot].num=in();
		a[tot].id=1;
	}
	sort(a+1,a+1+tot,cmp);
	int ans=0;
	int l=1, r=1, lin;
	while(l<=r && r<=tot)
	{
		while(r<=tot && a[r].id==0)
			r++;
		while(r<=tot && a[r].id==1)
			r++;
		ans+=(a[r-1].num-a[l].num);
		l=r;
	}
	printf("%d\n", ans);
	return (0);
}
/*
-1 1 2 5 9 11
0  1 0 0 1 1
ans=0;

*/ 
2022/10/1 23:34
加载中...