arc072 E - Alice in linear land

Problem Statement

Alice lives on a line. Today, she will travel to some place in a mysterious vehicle. Initially, the distance between Alice and her destination is D. When she input a number x to the vehicle, it will travel in the direction of the destination by a distance of x if this move would shorten the distance between the vehicle and the destination, and it will stay at its position otherwise. Note that the vehicle may go past the destination when the distance between the vehicle and the destination is less than x.

Alice made a list of N numbers. The i-th number in this list is di. She will insert these numbers to the vehicle one by one.

However, a mischievous witch appeared. She is thinking of rewriting one number in the list so that Alice will not reach the destination after N moves.

She has Q plans to do this, as follows:

Rewrite only the qi-th number in the list with some integer so that Alice will not reach the destination.
Write a program to determine whether each plan is feasible.

Constraints

1≤N≤5*105
1≤Q≤5*105
1≤D≤109
1≤di≤109(1≤i≤N)
1≤qi≤N(1≤i≤Q)
D and each di are integers.

题目大意

有个人要到达一个距离它D的地方,
对于每个操作 di d i
如果向前走能够更加靠近终点,
那么它就会走这一步。
问如在某个时刻修改操作 di d i
是否可以让这个人无法到达终点。

题解

我们定义一个一个东西
fi f i 表示最小的x,满足在x位置出发,
在执行操作 di...dn d i . . . d n 无法到达终点。
这个 fi f i 很好求,反过来求,
如果 fi+12>difi=fi+1+difi=fi+1 f i + 1 ∗ 2 > d i , 那 么 f i = f i + 1 + d i , 否 则 就 是 f i = f i + 1

code

#include<queue>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include <cstring>
#include <string.h>
#include <cmath>
#include <math.h>
#include <time.h>
#define ll long long
#define N 500003
#define M 103
#define db double
#define P putchar
#define G getchar
#define inf 998244353
using namespace std;
char ch;
void read(int &n)
{
    n=0;
    ch=G();
    while((ch<'0' || ch>'9') && ch!='-')ch=G();
    ll w=1;
    if(ch=='-')w=-1,ch=G();
    while('0'<=ch && ch<='9')n=(n<<3)+(n<<1)+ch-'0',ch=G();
    n*=w;
}

int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;}
ll abs(ll x){return x<0?-x:x;}
ll sqr(ll x){return x*x;}
void write(ll x){if(x>9) write(x/10);P(x%10+'0');}

int d[N],pos[N],f[N],q,n,m,x,y;

int main()
{
    read(n);read(m);

    pos[0]=m;
    for(int i=1;i<=n;i++)
        read(d[i]),pos[i]=min(pos[i-1],abs(pos[i-1]-d[i]));

    f[n+1]=1;
    for(int i=n;i;i--)
    {
        f[i]=f[i+1];
        if(d[i]<(f[i+1]<<1))f[i]+=d[i];
    }

    read(q);
    for(int i=1;i<=q;i++)
    {
        read(x);
        if(pos[x-1]>=f[x+1])puts("YES");
            else puts("NO");
    }

    return 0;
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值