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; }
原文地址:https://www.cnblogs.com/DyLoder/p/9951404.html
时间: 2024-11-08 23:35:43