hdu-5720 Wool(区间并+扫描线)
题目链接:
Wool
Time Limit: 8000/4000 MS (Java/Others)
Memory Limit: 262144/262144 K (Java/Others)
She is to cross a river and fetch golden wool from violent sheep who graze on the other side.
The sheep are wild and tameless, so Psyche keeps on throwing sticks to keep them away.
There are n sticks on the ground, the length of the i-th stick is ai.
If the new stick she throws forms a triangle with any two sticks on the ground, the sheep will be irritated and attack her.
Psyche wants to throw a new stick whose length is within the interval [L,R]. Help her calculate the number of valid sticks she can throw next time.
For each test case, the first line of input contains single integer n,L,R (2≤n≤10^5,1≤L≤R≤10^18).
The second line contains n integers, the i-th integer denotes ai (1≤ai≤10^18).
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const LL mod=998244353;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=1e5+10;
const int maxn=1e3+10;
const double eps=1e-6; int n;
LL l,r,a[N];
struct node
{
LL l,r;
}po[N];
int cmp(node x,node y)
{
if(x.l==y.l)return x.r<y.r;
return x.l<y.l;
}
int vis[N];
int main()
{
int t;
read(t);
while(t--)
{
mst(vis,0);
read(n);read(l);read(r);
For(i,0,n-1)read(a[i]);
sort(a,a+n);
For(i,1,n-1)
{
po[i].r=a[i]+a[i-1]-1;
po[i].l=a[i]-a[i-1]+1;
}
sort(po+1,po+n,cmp);
LL len=0;
For(i,1,n-1)
{
if(i==n-1)continue;
if(po[i].r<po[i+1].l)continue;
else
{
po[i+1].l=po[i].l;
po[i+1].r=max(po[i].r,po[i+1].r);
vis[i]=1;
}
}
For(i,1,n)
{
if(!vis[i])
{
if(po[i].l>r||po[i].r<l||po[i].l>po[i].r)continue;
LL L=max(po[i].l,l),R=min(po[i].r,r);
len=len+(R-L+1);
}
}
cout<<r-l+1-len<<"\n";
} return 0;
}
hdu-5720 Wool(区间并+扫描线)的更多相关文章
- hdu 5720 Wool
hdu 5720 问题描述 黎明时,Venus为Psyche定下了第二个任务.她要渡过河,收集对岸绵羊身上的金羊毛. 那些绵羊狂野不驯,所以Psyche一直往地上丢树枝来把它们吓走.地上现在有n n ...
- hdu 5720(贪心+区间合并)
Wool Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Subm ...
- HDU 5726 GCD 区间GCD=k的个数
GCD Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submis ...
- hdu 5720 BestCoder 2nd Anniversary Wool 推理+一维区间的并
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5720 题意:有n(n <= 105)个数 ,每个数小于等于 1018:问在给定的[L,R]区间中 ...
- HDU 1542 - Atlantis - [线段树+扫描线]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1542 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...
- hdu 3642 Get The Treasury(扫描线)
pid=3642" style="">题目链接:hdu 3642 Get The Treasury 题目大意:三维坐标系,给定若干的长方体,问说有多少位置被覆盖3次 ...
- cf1108e 线段树区间更新+扫描线
/* 有点像扫描线 思路:从左到右枚举每个点,枚举到点i时,把所有以i为起点的区间的影响删去 再加上以i-1为结尾的区间的影响 */ #include<bits/stdc++.h> usi ...
- HDU 6127 Hard challenge(扫描线)
http://acm.hdu.edu.cn/showproblem.php?pid=6127 题意: 有n个点,每个点有一个$(x,y)$坐标和一个权值,任意两点之间都有连线,并且连线的权值为两个顶点 ...
- hdu 1556(线段树之扫描线)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1556 Color the ball Time Limit: 9000/3000 MS (Java/Ot ...
随机推荐
- shell的while/for脚本的简单入门
shell的while/for脚本的简单入门 while [condition] dodone关键字break跳出循环,continue跳过循环的余下部分. for var in ...;do...d ...
- Perl、PHP、Python、Java和Ruby的比较
提问 ◆ Perl.Python.Ruby和PHP各自有何特点? ◆ 为什么动态语言多作为轻量级的解决方案? ◆ LAMP为什么受欢迎? ◆ Ruby on Rails为什么会流行? ◆ 编程语言的发 ...
- [TJOI2019]唱、跳、rap和篮球_生成函数_容斥原理_ntt
[TJOI2019]唱.跳.rap和篮球 这么多人过没人写题解啊 那我就随便说说了嗷 这题第一步挺套路的,就是题目要求不能存在balabala的时候考虑正难则反,要求必须存在的方案数然后用总数减,往往 ...
- Eclipse编译无响应
Eclipse编译无响应 Eclipse进程无响应结束进程后,或电脑直接断电后,重新打开Eclipse偶尔重新编译会卡进度,下面有一种解决方案: 首先找到卡进度的工程的名字,关闭Eclipse,找到该 ...
- Python3 MySQL 数据库连接 - PyMySQL 驱动 笔记
sql插入语句(推荐): str_mac = "nihao" # SQL 插入语句 sql = "INSERT INTO EMPLOYEE(FIRST_NAME, \ L ...
- filter过滤器实现特殊字符转义
web.xml <!-- 特殊字符转义或转换 --> <filter> <filter-name>XssFilter</filter-name> < ...
- iOS 内存管理实践
内存管理实践 尽管基本的概念在内存管理策略文章中简单得阐述了,但是还有一些实用的步骤让你更容易管理内存:有助于确保你的程序最大限度地减少资源需求的同时,保持可靠和强大. 使用“访问器方法”让内存管理更 ...
- 一道题目- Find the smallest range that includes at least one number from each of the k lists
You have k lists of sorted integers. Find the smallest range that includes at least one number from ...
- BUPT复试专题—内存分配(2014-2)
题目描述 在操作系统中,内存分配是非常重要的工作.己知内存空间由N个内存块组成,这些内存块从1到N编号.进行内存分配时,操作系统将选择一块大小足够的内存全部分配给请求内存的进程.例如,当进程请求10M ...
- 在chrome中屏蔽百度推荐
在chrome中屏蔽百度推荐 方法1:可以使用adblock plus来进行屏蔽: 需要将chrome的扩展程序打开为调试者模式: 下载地址:http://chromecj.com/productiv ...