1. 程式人生 > >Educational Codeforces Round 46 C - Covered Points Count

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; }