Bryce1010模板

http://codeforces.com/problemset/problem/1000/C

题意:问你从[l,r]区间的被多少条线覆盖,列出所有答案。

思路:类似括号匹配的做法

#include <bits/stdc++.h>

using namespace std;

#define ll long long

const ll MAXN=2e5+10;
struct Node
{
ll num;
ll dir;//0左1右
//ll cnt;
}node[MAXN*2];
ll cnt[MAXN*2]; bool cmp(Node a,Node b)
{
if(a.num!=b.num)return a.num<b.num;
else return a.dir<b.dir;
} int main()
{
ll n;
cin>>n;
for(ll i=0;i<2*n;i++)
{
if(i&1)
{
cin>>node[i].num;
node[i].dir=1;
}
else
{
cin>>node[i].num;
node[i].dir=0;
}
}
sort(node,node+2*n,cmp);
// for(ll i=0;i<2*n;i++)
// cout<<node[i].num<<" "<<node[i].dir<<endl;; ll tot=0;
for(ll i=0;i<2*n;i++)
{
if(node[i].dir==0)//左
{
if(node[i-1].dir==0)
cnt[tot]+=node[i].num-node[i-1].num;
else if(node[i-1].dir==1)
cnt[tot]+=node[i].num-node[i-1].num-1;
tot++;
}
else//右
{
if(node[i-1].dir==1)
cnt[tot]+=node[i].num-node[i-1].num;
else
cnt[tot]+=node[i].num-node[i-1].num+1;
tot--;
} } cout<<cnt[1];
for(ll i=2;i<=n;i++)
cout<<" "<<cnt[i];
cout<<endl; return 0;
}

Educational Codeforces Round 46 (Rated for Div. 2) C. Covered Points Count的更多相关文章

  1. Educational Codeforces Round 50 (Rated for Div. 2) E. Covered Points

    注释上都有解析了,就不写了吧,去重的问题就用set解决,并且呢第i个线段最多和其他线段产生i-1个交点,n^2logn. #include <cmath> #include <cst ...

  2. Educational Codeforces Round 46 (Rated for Div. 2) E. We Need More Bosses

    Bryce1010模板 http://codeforces.com/contest/1000/problem/E 题意: 给一个无向图,求图的最长直径. 思路:对无向图缩点以后,求图的最长直径 #in ...

  3. Educational Codeforces Round 46 (Rated for Div. 2) B. Light It Up

    Bryce1010模板 http://codeforces.com/problemset/problem/1000/B 思路:先用两个数组sumon[]和sumoff[]将亮着的灯和灭的灯累计一下. ...

  4. Educational Codeforces Round 46 (Rated for Div. 2) A. Codehorses T-shirts

    Bryce1010模板 http://codeforces.com/problemset/problem/1000/A 题意: 问你将一种类型的衣服转换成另一种的最小次数. #include<b ...

  5. Educational Codeforces Round 46 (Rated for Div. 2)

    A - Codehorses T-shirts 思路:有相同抵消,没有相同的对答案+1 #include<bits/stdc++.h> #define LL long long #defi ...

  6. Educational Codeforces Round 46 (Rated for Div. 2) D. Yet Another Problem On a Subsequence

    这个题是dp, dp[i]代表以i开始的符合要求的字符串数 j是我们列举出的i之后一个字符串的开始地址,这里的C是组合数 dp[i] += C(j - i - 1, A[i]] )* dp[j]; # ...

  7. Educational Codeforces Round 46 (Rated for Div. 2) D

    dp[i]表示一定包含第I个点的好的子序列个数,那么最终答案就是求dp[0] + dp[1] + .... + dp[n-1] 最终的子序列被分成了很多块,因此很明显我们枚举第一块,第一块和剩下的再去 ...

  8. Educational Codeforces Round 72 (Rated for Div. 2)-D. Coloring Edges-拓扑排序

    Educational Codeforces Round 72 (Rated for Div. 2)-D. Coloring Edges-拓扑排序 [Problem Description] ​ 给你 ...

  9. Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...

随机推荐

  1. java中使用反射获取pojo(实体)类的全部字段值

    说起反射.不得不说它实在是太强大了,通过反射就能够轻轻松松拿到各种东东,假设你想在项目中解除对某个类的依赖,能够考虑用反射. 今天跟大家分享的是通过java中的反射,获取pojo类的全部字段值. 为什 ...

  2. 微软开源 Try .NET - 创建交互式.NET文档

    微软近日开源了一个新平台--Try .NET,该平台可以让开发者在线上编写并运行 .NET 代码.微软介绍,Try .NET 是一个可嵌入的代码运行器,不仅可以直接在线上对自己或者他人的代码进行编辑. ...

  3. appium 控件定位

    转自:http://www.2cto.com/kf/201410/340345.html AppiumDriver的各种findElement方法的尝试,尝试的目标应用是SDK自带的Notepad应用 ...

  4. reviews of learn python3 the hard way

    Almost every time,I try my best to write a long review of the book I have read. But this time I want ...

  5. Vue 之 npm 及 安装的包

    1  npm相关 1.1 npm 是 基于Node.js 的,所以要先安装Node.js 在浏览器地址栏输入https://nodejs.org/en/, 进入Node.js官网后,点击下载左边的稳定 ...

  6. Mac中配置eclipse的php开发环境

    1.mac中自带php和apache,不过版本不是最新的. 2.打开apache配置文件中php相关设置,并设置php的工程目录为你想要的目录 3.复制php.ini.default为php.ini, ...

  7. linux下使用无线网卡的命令行方法(wifi,iwconfig)

    原文地址:linux下使用无线网卡的命令行方法(wifi,iwconfig) 作者:andyhzw (1)首先关闭开发板的有线网卡 [root@FriendlyARM /]# ifconfig eth ...

  8. UVA11624 Fire! —— BFS

    题目链接:https://vjudge.net/problem/UVA-11624 题解: 坑点:“portions of the maze havecaught on fire”, 表明了起火点不唯 ...

  9. jdk8新特性Stream

    Stream的方法描述与实例 1,filter  过滤 Person p1 = new Person(); p1.setName("P1"); p1.setAge(10); Per ...

  10. ajax验证用户名 当用户名框的数据改变时 执行ajax方法

    ajax验证用户名 当用户名框的数据改变时 执行ajax方法 <html xmlns="http://www.w3.org/1999/xhtml" ><head ...