E - Gophers
Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87794#problem/E

Description

Dick Dastardly wants to bedevil poor Bytean gophers. These nice little creatures live in holes in the upper parts of High Bytemountains. Dick has found a mountain ridge with n gopher holes located along a straight line (for simplicity, we index the holes from 1 to n, from west to east). Dick plans to torture gophers using rock & roll music. He has bought m CD players, put a different Bytels’ album in each of them and arranged the CD players along the ridge. The music from a CD player disturbs gophers located in holes distant by at most l meters from it. Feeling troubled, the gophers asked you to check in which holes they will not be able to sleep well during this winter. But now Dick Dastardly wants to make even more mess. . . He will move the CD players from time to time. The gophers were able to steal Dick’s secret plan and now they know precisely that on the morning of the i-th day Dick will take the CD player located pi meters from the hole number 1 and will put it at a point located ri meters from that hole. Help the gophers and count the number of holes in which they will not be able to fall asleep after each such operation.

Input

The first line of input contains four integers n, m, d and l (2 ¬ n; m ¬ 500 000, 1 ¬ d ¬ 500 000, 1 ¬ l ¬ 109 ) representing the number of gophers’ holes, the number of Dick’s CD players, the number of days and the range of a CD player, respectively. The second line of input contains n − 1 integers x2; x3; : : : ; xn (0 < x2 < x3 < : : : < xn ¬ 109 ) denoting the distances of the holes 2; 3; : : : ; n from the hole number 1. The third line contains m integers z1; z2; : : : ; zm (0 ¬ z1 < z2 < : : : < zm ¬ 109 ) denoting the distances of the consecutive CD players from the hole number 1. All the CD players are located to the east of this hole. Next, d lines follow. The i-th of these lines contains two integers pi and ri (0 ¬ pi ; ri ¬ 109 , pi 6= ri ) meaning that in the beginning of the i-th day Dick is going to move the CD player located pi meters from the hole number 1 to the point located ri meters to the east from that hole. You may assume that before every such operation there is a CD player at the position pi and there are no CD players at the position ri .

Output

Your program should output d + 1 lines. The line number i (for i = 1; 2; : : : ; d) should contain one integer representing the number of holes in which no gopher would be able to sleep well during the night before the i-th Dick’s operation. The last line should contain this number after the last Dick’s operation.

Sample Input

5 3 4 1 2 5 6 11 2 4 8 2 1 4 10 8 6 1 8

Sample Output

2 3 3 5 3

HINT

题意

给你n个点,m个长度为l的线段

有Q次询问,每次询问就是把x位置的线段挪到y位置,然后问你这些线段覆盖了多少个点

题解

首先,我们知道每一个线段的长度都是一样的,而且题目给了,没有任何两条线段是在同一个点的,于是我们就可以用set做

对于每一个线段,他覆盖的区域实际上是[max(a[i-1]+l,a[i]-l),min(a[i+1]-l,a[i]+l)]这个区域

然后我们用set去维护就好了

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 1000001
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
const int inf=0x7fffffff; //нчоч╢С
//const int inf=0x3f3f3f3f;
/* inline void P(int x)
{
Num=0;if(!x){putchar('0');puts("");return;}
while(x>0)CH[++Num]=x%10,x/=10;
while(Num)putchar(CH[Num--]+48);
puts("");
}
*/
//**************************************************************************************
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
ll n,m,q,l;
ll aa[maxn];
ll ans=;
ll d[maxn];
ll C(ll l,ll r)
{
if(l>aa[n])
return ;
if(r<aa[])
return ;
if(l>r)
return ;
ll L,R;
if(l<=)
L=;
else
L=lower_bound(aa+,aa+n+,l)-aa;
if(r>=aa[n])
R=n;
else
R=(upper_bound(aa+,aa+n+,r)-aa)-;
return R-L+;
}
set<ll> S;
int main()
{
n=read(),m=read(),q=read(),l=read();
S.insert(-inf);
aa[]=;
for(int i=;i<=n;i++)
aa[i]=read();
S.insert(inf);
ll tmp=;
for(int i=;i<=m;i++)
{
ll x=read();
S.insert(x);
if(i==)
ans+=C(x-l,x+l);
else
ans+=C(max(tmp+l+1LL,x-l),x+l);
tmp=x;
}
printf("%lld\n",ans);
for(int i=;i<=q;i++)
{
ll x=read();
ll c=*++S.lower_bound(x);
ll d=*--S.lower_bound(x);
ans-=C(max(d+l+1LL,x-l),min(c-l-1LL,x+l));
int e=*S.lower_bound(x);
S.erase(e);
x=read();
c=*S.lower_bound(x);
d=*--S.lower_bound(x);
ans+=C(max(d+l+1LL,x-l),min(c-l-1LL,x+l));
printf("%lld\n",ans);
S.insert(x);
}
}

Codeforces Gym 100523E E - Gophers SET的更多相关文章

  1. Codeforces Gym 101252D&&floyd判圈算法学习笔记

    一句话题意:x0=1,xi+1=(Axi+xi%B)%C,如果x序列中存在最早的两个相同的元素,输出第二次出现的位置,若在2e7内无解则输出-1. 题解:都不到100天就AFO了才来学这floyd判圈 ...

  2. Codeforces Gym 101190M Mole Tunnels - 费用流

    题目传送门 传送门 题目大意 $m$只鼹鼠有$n$个巢穴,$n - 1$条长度为$1$的通道将它们连通且第$i(i > 1)$个巢穴与第$\left\lfloor \frac{i}{2}\rig ...

  3. Codeforces Gym 101623A - 动态规划

    题目传送门 传送门 题目大意 给定一个长度为$n$的序列,要求划分成最少的段数,然后将这些段排序使得新序列单调不减. 考虑将相邻的相等的数缩成一个数. 假设没有分成了$n$段,考虑最少能够减少多少划分 ...

  4. 【Codeforces Gym 100725K】Key Insertion

    Codeforces Gym 100725K 题意:给定一个初始全0的序列,然后给\(n\)个查询,每一次调用\(Insert(L_i,i)\),其中\(Insert(L,K)\)表示在第L位插入K, ...

  5. Codeforces gym 101343 J.Husam and the Broken Present 2【状压dp】

     2017 JUST Programming Contest 2.0 题目链接:Codeforces gym 101343 J.Husam and the Broken Present 2 J. Hu ...

  6. codeforces gym 100553I

    codeforces gym 100553I solution 令a[i]表示位置i的船的编号 研究可以发现,应是从中间开始,往两边跳.... 于是就是一个点往两边的最长下降子序列之和减一 魔改树状数 ...

  7. CodeForces Gym 100213F Counterfeit Money

    CodeForces Gym题目页面传送门 有\(1\)个\(n1\times m1\)的字符矩阵\(a\)和\(1\)个\(n2\times m2\)的字符矩阵\(b\),求\(a,b\)的最大公共 ...

  8. Codeforces GYM 100876 J - Buying roads 题解

    Codeforces GYM 100876 J - Buying roads 题解 才不是因为有了图床来测试一下呢,哼( 题意 给你\(N\)个点,\(M\)条带权边的无向图,选出\(K\)条边,使得 ...

  9. codeforces Gym 100187J J. Deck Shuffling dfs

    J. Deck Shuffling Time Limit: 2   Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/pro ...

随机推荐

  1. css中position:relative的真正理解

    其实话说一直以来也没真正去理解好position:relative的用法的真实意义. 我想很多人实实在在用的多都是position:relative和position:absolute结合起来一起用的 ...

  2. mbr grub的区别

    mbr是磁盘的物理扇区,不是程序名: 因为BIOS很小,功能有限,为了完成加载操作系统的功能,就产生了mbr: bios检测到一个硬盘后,将硬盘的0柱面.0磁头.1扇区的内容经过简单判断后, 至内存中 ...

  3. 高性能Server---Reactor模型-----Socket

    高性能Server---Reactor模型   原文地址:http://www.ivaneye.com/2016/07/23/iomodel.html 无处不在的C/S架构 在这个充斥着云的时代,我们 ...

  4. logback.xml配置

    一:根节点<configuration>包含的属性: scan: 当此属性设置为true时,配置文件如果发生改变,将会被重新加载,默认值为true. scanPeriod: 设置监测配置文 ...

  5. CXF之jaxws:endpoint对spring bean的引用

    由于CXF对spring的无缝支持,CXF的使用,经常与spring捆绑在一起.随之而起的,自然是想在jaxws:endpoint中引用spring bean.在CXF提供的HelloWorld例子中 ...

  6. 对delegate进行扩展 打造通用的"计时完成"方法 z

    让用户尽量少打字 每次让用户输入这么多信息的确很糟糕, 可以改进一下设计: 服务器IP和用户名可以存放在配置文件里面, 初始化的时候默认加载到相应的文本框中; 从安全角度考虑, 密码必须经过用户手动输 ...

  7. 对LR analysis的平均事务响应时间和summary中时间值不同的解释

    最近在做性能测试对LR结果分析时,又碰到了关于summary里与平均事务响应时间中各交易的响应时间值不同的问题.在此做个记录. 若交易中设置了思考时间,分析时需要注意查看是否过滤思考时间. 设置是否包 ...

  8. HDU5764 After a Sleepless Night 树形乱搞题

    分析(官方题解): 假设根已确定,可以发现新树若合法,需满足以下性质:根节点是n:儿子的值不大于父亲:具有相同值的节点形成一条链,并且链不会发生“分叉”(即有多个最低点).所以对于新树中有出现的值x, ...

  9. 使用DDMS测试安卓手机APP的性能(android)

    安装/配置: 通过另外一个工具也可以测试手机客户端APP的性能,这就是android开发包中的DDMS工具(Dalvik Debug Monitor Service),先来说一下android开发包的 ...

  10. cocos2d-x 详解之 CCAction(动作)

    关于动作部分,总的来说使用起来比较简单,创建一个动作,然后让可渲染节点如精灵去执行这个动作即可.cocos2dx提供了很多类型的动作,使用起来也很方便.本节重点介绍动作CCAction的子类之一时间动 ...