当前位置:首页 » 《随便一记》 » 正文

AtCoder Beginner Contest 221 D(思维_cosx_的博客

19 人参与  2022年03月20日 10:35  分类 : 《随便一记》  评论

点击全文阅读


D - Online games
题解

code:

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 2e5 + 9;

int ans[maxn];
void work()
{
	int n;cin >> n;
	int a, b;
	vector <pair<int,int> > v;
	int cnt = 0;
	for(int i = 1; i <= n; ++i)
	{
		cin >> a >> b;
		v.push_back({a, 1});
		v.push_back({a + b, -1});
	}
	sort(v.begin(), v.end());
	/*cout << endl;
	for(int i = 0; i < v.size(); ++i)
		cout << v[i].first << " " << v[i].second << endl;*/
	for(int i = 0; i < v.size() - 1; ++i)
	{
		cnt += v[i].second;
		ans[cnt] += (v[i + 1].first - v[i].first);
	}
	for(int i = 1; i <= n; ++i)
		cout << ans[i] << " ";
}

int main()
{
	ios::sync_with_stdio(0);
	work();
	return 0;
}
/*
1 2
  2 3 4
    3
*/

点击全文阅读


本文链接:http://zhangshiyu.com/post/36374.html

题解  long  namespace  
<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

关于我们 | 我要投稿 | 免责申明

Copyright © 2020-2022 ZhangShiYu.com Rights Reserved.豫ICP备2022013469号-1