help me!!!!!!!!!!!!!!!!!!!!!!

题目总版

UKE_bound @ 2024-09-18 12:26:38

站外题

#include<bits/stdc++.h>
using namespace std;
int n,q,s,t;
long long a[200005];
int dx(int dh){
    if(dh>0){
        return -dh*s;
    }else{
        return -dh*t;
    }
} 
int main(){
    cin>>n>>q>>s>>t;
    for(int i=0;i<=n;i++){
        cin>>a[i];
    }
    for(int i=n;i>=1;i--){
        a[i]-=a[i-1];
    }
    int v=0;
    for(int i=1;i<=n;i++){
        v+=dx(a[i]);
    }
    for(int i=1;i<=q;i++){
        int l,r,x;
        cin>>l>>r>>x;
        int v0=v;
        v0-=dx(a[l]);
        v0+=dx(a[l]+x);
        if(r!=n+1){
            v0-=dx(a[r+1]);
            v0+=dx(a[r+1]-x);
        }
        cout<<v0<<endl;
    }
    return 0; 
}

求调


by 0Io_oI0 @ 2024-09-18 13:12:14

#include <iostream>
using namespace std;
int n, q;
long long s,t;
long long a[200005],d[200005];
int l,r;
long long x,ans;
long long cal(long long d)
{
    if(d > 0)
    {
        return -d * s;
    }
    else
    {
        return -d * t;
    }
}
int main()
{
    cin >> n >> q >> s >> t;
    for(int i = 0;i <= n;i++)
    {
        cin >> a[i] ;
    }
    for(int i = 1;i <= n;i++)
    {
        d[i] = a[i] - a[i - 1];
        ans += cal(d[i]);

    }
    for(int i = 0;i < q;i++)
    {
        cin >> l >> r >> x;
        ans -= cal(d[l]);
        d[l] += x;
        ans += cal(d[l]);
        if(r < n)
        {
            ans -= cal(d[r + 1]);
            d[r + 1] -= x;
            ans += cal(d[r + 1]);
        }
        cout << ans << endl;
    }
    return 0;
}

by 违规用户名Jd8@z5Fw @ 2024-09-18 16:58:41

@zhangjiaan @zhangjiaan @kkksc03 @lin_toto @chenzhe @yummy @soha


by tsh_ @ 2024-09-18 18:03:44

@kkksc03_e ??????????????????????????


by BJ6127SHEVCA @ 2024-09-21 18:40:47

@违规用户名Jd8@z5Fw

奖项:jc小达人


|