CF1000C Covered Points Count

刚刚看到这题时感觉特别难…经过大约10分钟的思考…
水题QAQ 不多说了上代码呀QAQ

#include<iostream>//标准模板呀QAQ
#include<cstdio>
#include<cmath>
#include<string.h>
#include<algorithm>
#define For(i,f,l) int pd=(f<l)*1+(l<=f)*-1;for(i=f;i!=l+pd;i+=pd)
using namespace std;
void read(long long &n)
{
  long long x=0;int w=1; char ch=0;
  while(!isdigit(ch)){if(ch=='-')w=-1;if(ch=='+')w=1;ch=getchar();}
  while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
  n=w*x;
}
void write(long long x)
{
  if(x<0){putchar('-');x=-x;}
  if(x>9)write(x/10);
  putchar(x%10+'0');
}
struct Sort//定义一个类
{
  long long w,a;
  //w为位置,a为做的操作
}p[1000000];
bool cmp(Sort &a,Sort &b)
{
  return a.w<b.w;//按w的大小排序
}
int i,j,k,sum=0,m;
long long ans[1000000],l,r,n,now=0;//注意开long long
int main()
{
  read(n);
  for(i=1;i<=n;i++)
  {
  	read(l);read(r);
  	sum++;
    p[sum].w=l;
  	p[sum].a=1;//区间起始位置为++
  	sum++;
  	p[sum].w=r+1;//结束位置为--
  	p[sum].a=-1;
  }
  sort(p+1,p+sum+1,cmp);//排序
  l=p[1].w;//当前位置
  now=p[1].a;//当前覆盖层数
  for(i=2;i<=sum;i++)
  {
  	ans[now]+=p[i].w-l;//当前层数的个数为前后操作位置只差
  	l=p[i].w;
  	now+=p[i].a;
  }
  for(i=1;i<=n;i++)cout<<ans[i]<<" ";//输出呀QAQ
  return 0;
}

算是一道大水题呀QAQ…
建议去做一下借教室,用了差不多的思想呀…

猜你喜欢

转载自blog.csdn.net/sxy__orz/article/details/86685203
今日推荐