我超,论这题数据有多水
查看原帖
我超,论这题数据有多水
527243
Iamzzr楼主2022/10/2 07:47

我对题解产生了一些疑问,遂将代码中我产生疑问的地方进行了一些更改,然后提交了一下,AC 了。

但是我刚才又想了一下,感觉更改过后,代码是错的,我试了一下样例 2,好家伙,样例都过不去了。

#include <bits/stdc++.h>
using namespace std;
const int N=100005;
struct tree
{
    int v;
    int num,lazy;
}t[N<<2];
int n,res,last,ans,S[N],A[N];
int gi()
{
    int x=0;char ch=getchar();
    while (ch<'0'||ch>'9') ch=getchar();
    while (ch>='0'&&ch<='9')
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x;
}
void Update(int now)
{
    if (t[now<<1].v>=t[now<<1|1].v) //等于取哪边无所谓 
    {
        t[now].v=t[now<<1].v;t[now].num=t[now<<1].num;
    }
    else
    {
        t[now].v=t[now<<1|1].v;t[now].num=t[now<<1|1].num;
    }
}
void Build(int now,int l,int r)
{
    if (l==r)
    {
        t[now].v=2*S[l]+A[l];
        t[now].num=l;
        return;
    } 
    int mid=l+r>>1;
    Build(now<<1,l,mid);
    Build(now<<1|1,mid+1,r);
    Update(now);
}
void Push_down(int now)
{
    t[now<<1].v+=t[now].lazy;
    t[now<<1|1].v+=t[now].lazy;
    t[now<<1].lazy+=t[now].lazy;
    t[now<<1|1].lazy+=t[now].lazy;
    t[now].lazy=0;
}
void Change(int now,int l,int r){
    /*if (l>res)
    {
        t[now].v-=2*(S[res]-S[last]);
        t[now].lazy-=2*(S[res]-S[last]);
        return;
    }*/
    if (l > r) return;
    if (l==r)
    {
        t[now].v=A[l];
        return;
    }
    if (t[now].lazy!=0) Push_down(now);
    int mid=l+r>>1;
    Change(now<<1,l,mid);
    Change(now<<1|1,mid+1,r);
    Update(now);
}
void Delete(int now,int l,int r)
{
    if (l==res&&r==res)
    {
        t[now].v=0;
        return;
    }
    if (t[now].lazy!=0) Push_down(now);
    int mid=l+r>>1;
    if (res<=mid) Delete(now<<1,l,mid);
    else Delete(now<<1|1,mid+1,r);
    Update(now);
}
int main()
{
    n=gi();
    for (int i=1;i<=n;i++)
      S[i]=gi();
    for (int i=1;i<=n;i++)
      A[i]=gi();
    Build(1,1,n);
    for (int i=1;i<=n;i++)
    {
        printf("%d ",t[1].v+ans);
        ans+=t[1].v;
        res=t[1].num;
        cout << res << " " << last << endl;
        if (res>last)
        {
            Change(1,1,n);
            last=res;
        }
        Delete(1,1,n);
    }
    return 0;
}

请求加强数据

2022/10/2 07:47
加载中...