Educational Codeforces Round 46 C - Covered Points Count

Posted dyloder

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Educational Codeforces Round 46 C - Covered Points Count相关的知识,希望对你有一定的参考价值。

C - Covered Points Count

emmm 好像是先离散化一下 注意 R需要+1 这样可以确定端点

emmm 扫描线?瞎搞一下?

#include<bits/stdc++.h>
using namespace std;
#define maxn 4000005
#define LL long long
LL  a[maxn],b[maxn],ll[maxn],rr[maxn],c[maxn];
LL  x[maxn],y[maxn];
vector<LL >q;
int main(){
   LL  n;
   cin>>n;
   for(LL  j=0;j<n;j++){
      cin>>a[j]>>b[j];
      b[j]++;
      q.push_back(a[j]);
      q.push_back(b[j]);
   }
   q.push_back(0);
   sort(q.begin(),q.end());
   q.erase(unique(q.begin(),q.end()),q.end());
   for(LL  j=0;j<n;j++){
      LL  i=lower_bound(q.begin(),q.end(),a[j])-q.begin();
      LL  k=lower_bound(q.begin(),q.end(),b[j])-q.begin();
      //x[j]=i,y[j]=k;
      ll[i]++;
      rr[k]++;
   }
   LL  ans=0;
   LL  i=0;
   memset(c,0,sizeof(c));
   memset(y,0,sizeof(y));
   for(LL  j=0;j<q.size();j++){
      if(j==0) x[j]+=ll[j]-rr[j];
      else x[j]+=ll[j]-rr[j]+x[j-1];
     // cout<<x[j]<<endl;
   }
   for(LL  j=0;j<q.size()-1;j++){
     // cout<<x[j]<<" "<<q[j+1]<<" "<<q[j]<<endl;
      y[x[j]]+=q[j+1]-q[j];
   }
   for(LL j=1;j<=n;j++){
     cout<<y[j]<<" ";
   }
   cout<<endl;
}

 

以上是关于Educational Codeforces Round 46 C - Covered Points Count的主要内容,如果未能解决你的问题,请参考以下文章

Educational Codeforces Round 7 A

Educational Codeforces Round 7

Educational Codeforces Round 90

Educational Codeforces Round 33

Codeforces Educational Codeforces Round 54 题解

Educational Codeforces Round 27