codeforces 1000 C. Covered Points Count(线段问题)

http://codeforces.com/contest/1000/problem/C
题意:给出n条线段,问被覆盖1~n次的点有多少个

思路:考虑将所有点放进数组中排序,cnt记录现在被覆盖次数,那么该cnt数量即为这次y-x+1,但是会遇到一个问题,一个点可能会被重复计算 如 1 3,3 5,3 7那么3这个位置的点就会被重复计算,那么我们只需要将右端点右移,数量为y-x,就算一个点出现多次也不会被重复计算

#include<bits/stdc++.h>
#define fi first
#define se second
#define log2(a) log(n)/log(2)
#define show(a) cout<<a<<endl;
#define show2(a,b) cout<<a<<" "<<b<<endl;
#define show3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl;
#define tim printf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
using namespace std;

typedef long long ll;
typedef long long LL;
typedef pair<ll, ll> P;
typedef pair<P, ll> LP;
const ll inf = 1e18;
const int N = 2e6 + 10;
const ll mod = 1e9+7;
const int base = 131;
const double pi = acos ( -1 );
const double eps = 1e-8;
inline ll mul(ll x,ll y) { return (x*y-(ll)((long double)x*y/mod)*mod+mod)%mod;}
inline ll ksm(ll a,ll b) {ll ans=1;while(b){if(b&1)ans=mul(ans,a);a=mul(a,a),b>>=1;}return ans;}

#define a(i,j) a[(i-1)*m+(j)]
#define b(i,j) b[(i-1)*m+(j)]

unordered_map<ll, ll> mp;


ll n, m,x,y,z,cx,k,a[N],b[N],c[N];
ll ans,t,flag;
ll num[N],vis[N];
vector<ll> v;
ll sum,cnt;
ll res[N];
P p[N];

int main()
{


	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	cin>>n;
	for(int i=1;i<=2*n;i+=2)
	{
		cin>>p[i].fi;
		p[i].se=1;
		cin>>p[i+1].fi;
		p[i+1].fi++;
		p[i+1].se=-1;
	}
	sort(p+1,p+2*n+1);

	cnt=1;
	for(int i=2;i<=2*n;i++)
	{
		num[cnt]+=p[i].fi-p[i-1].fi;
		cnt+=p[i].se;
	}

	for(int i=1;i<=n;i++)
	{
		cout<<num[i]<<" ";
	}

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值