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. 杭电1596find the safest road(spfa)

    find the safest road Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  2. HDU 3249 Test for job (有向无环图上的最长路,DP)

     解题思路: 求有向无环图上的最长路.简单的动态规划 #include <iostream> #include <cstring> #include <cstdlib ...

  3. java 调用ant的自己定义task,默认不是build.xml 的一点问题

    java  调用ant的自己定义task, File buildFile = new File(".//ee-build.xml");         // 创建一个ANT项目   ...

  4. IE8与vs2005冲突 添加MFC类向导错误解决方法—— internet explorer脚本错误

    IE8 与 VS2005 冲突问题解决方法 问题表现为: MFC类向导添加类时,出现“当前页面的脚本发生错误”,进入MFC类向导后上方有一个小黄条“此网站的某个加载项运行失败.请检查"Int ...

  5. hihocode #1388 : Periodic Signal NTT

    #1388 : Periodic Signal   描述 Profess X is an expert in signal processing. He has a device which can ...

  6. Statelessness Provide credentials with the request. Each request MUST stand alone and should not be affected from previous conversation happened from same client in past.

    The server never relies on information from previous requests. Statelessness As per the REST (REpres ...

  7. 20170225-第三件事:FR0002测试

    第三件事:FR0002测试             MATNR WERKS BERID 800000217 I010               问题,上for all entrys…       1 ...

  8. BAPI_PO_CEATE 与PO_1

  9. Jmeter性能测试-GC相关

    1.GC相关 HotSpot虚拟机将其物理上划分为两个–新生代(young generation)和老年代(old generation).新生代(Young generation): 绝大多数最新被 ...

  10. CentOS7 安装和配置Tomcat

    1.官网下载Tomcat的压缩包 https://tomcat.apache.org/download-70.cgi 2.使用Xftp5把下载的压缩包上传到 /usr/soft (soft文件夹自己新 ...