Educational Codeforces Round 46 (Rated for Div. 2) C. Covered Points Count
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的更多相关文章
- Educational Codeforces Round 50 (Rated for Div. 2) E. Covered Points
注释上都有解析了,就不写了吧,去重的问题就用set解决,并且呢第i个线段最多和其他线段产生i-1个交点,n^2logn. #include <cmath> #include <cst ...
- Educational Codeforces Round 46 (Rated for Div. 2) E. We Need More Bosses
Bryce1010模板 http://codeforces.com/contest/1000/problem/E 题意: 给一个无向图,求图的最长直径. 思路:对无向图缩点以后,求图的最长直径 #in ...
- Educational Codeforces Round 46 (Rated for Div. 2) B. Light It Up
Bryce1010模板 http://codeforces.com/problemset/problem/1000/B 思路:先用两个数组sumon[]和sumoff[]将亮着的灯和灭的灯累计一下. ...
- Educational Codeforces Round 46 (Rated for Div. 2) A. Codehorses T-shirts
Bryce1010模板 http://codeforces.com/problemset/problem/1000/A 题意: 问你将一种类型的衣服转换成另一种的最小次数. #include<b ...
- Educational Codeforces Round 46 (Rated for Div. 2)
A - Codehorses T-shirts 思路:有相同抵消,没有相同的对答案+1 #include<bits/stdc++.h> #define LL long long #defi ...
- 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]; # ...
- Educational Codeforces Round 46 (Rated for Div. 2) D
dp[i]表示一定包含第I个点的好的子序列个数,那么最终答案就是求dp[0] + dp[1] + .... + dp[n-1] 最终的子序列被分成了很多块,因此很明显我们枚举第一块,第一块和剩下的再去 ...
- Educational Codeforces Round 72 (Rated for Div. 2)-D. Coloring Edges-拓扑排序
Educational Codeforces Round 72 (Rated for Div. 2)-D. Coloring Edges-拓扑排序 [Problem Description] 给你 ...
- 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 ...
随机推荐
- linux 输入子系统(3) button platform driver
button platform driver 一般位于driver/input/keyboard/gpio_keys.c /*用于按键事件的上报,它将在按键的中断发生后被调用.其中逻辑就是获取到按键类 ...
- 项目Beta冲刺(团队1/7)
项目Beta冲刺(团队1/7) 团队名称: 云打印 作业要求: 项目Beta冲刺(团队) 作业目标: 完成项目Beta版本 团队队员 队员学号 队员姓名 个人博客地址 备注 221600412 陈宇 ...
- AIM Tech Round (Div. 2) C. Graph and String
C. Graph and String time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- CentOS 7.2 安装Gerrit 2.14.6
1.环境 本文使用VMWare虚拟机进行实验. 2核CPU,4GB内存,20GB硬盘,IP:192.168.159.131 CentOS 7.2最小安装(CentOS-7-x86_64-Minimal ...
- react native与原生的交互
一.交互依赖的重要组件 react native 中如果想要调用ios 中相关的方法,必须依赖一个重要的组件nativemodules import { NativeModules } from ' ...
- css3中animation的应用
1.css3 的相关属性: 相关代码: div { animation-name: myfirst; //动画的名称 animation-duration: 5s; //动画一个周期需要5秒 anim ...
- mysql 5.5升级到5.7版本操作流程
一.备份原来 phpStudy 中 MySQL 安装目录 二.把下载的 MySQL 压缩文件解压至 phpStudy 下的 MySQL目录,复制 my-default.ini ,重命名为 my.ini ...
- NSString -- UILabel中字体有多种颜色,字符串自动计算高度/换行
一:UILabel中字体有多种颜色 UILabel *label = [[UILabel alloc] init]; label.frame = CGRectMake(, , , ); label.b ...
- web 基本概念辨异 —— URI 与 URL
两者的相同点: 都是唯一的,对资源(R:Resource)起到唯一的标识作用: 两者的不同点: URL 是 URI 的子集(URI 是父类,URL 是子类),是一种特定的实现形式: URI 可以是身份 ...
- bzoj2004公交线路——DP+矩阵加速递推
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2004 求方案数,想到DP: 因为两个站间距离<=p,所以每p个站中所有车一定都会停靠至 ...