Submission #170646

#TimeUsernameProblemLanguageResultExecution timeMemory
170646mdn2002Foehn Phenomena (JOI17_foehn_phenomena)C++14
30 / 100
1083 ms10232 KiB
#include<bits/stdc++.h>
using namespace std;
const long long mod=998244353;
long long n,q,s,t,tree[800005],lazy[800005],ans;
void up(int nod,int l,int r,int x,int y,long long val)
{
    if(lazy[nod]!=0)
    {
        tree[nod]+=lazy[nod];
        if(l!=r)
        {
            lazy[nod*2]+=lazy[nod];
            lazy[nod*2+1]+=lazy[nod];
        }
        lazy[nod]=0;
    }
    if(r<x||y<l)return;
    if(x<=l&&r<=y)
    {
        tree[nod]+=val;
        if(l!=r)
        {
            lazy[nod*2]+=val;
            lazy[nod*2+1]+=val;
        }
        return;
    }
    int mid=(l+r)/2;
    up(nod*2,l,mid,x,y,val);
    up(nod*2+1,mid+1,r,x,y,val);
    tree[nod]=tree[nod*2]+tree[nod*2+1];
}
long long qu(int nod,int l,int r,int x)
{
    if(lazy[nod]!=0)
    {
        tree[nod]+=lazy[nod];
        if(l!=r)
        {
            lazy[nod*2]+=lazy[nod];
            lazy[nod*2+1]+=lazy[nod];
        }
        lazy[nod]=0;
    }
    if(x<l||r<x)return 0;
    if(l==r)return tree[nod];
    int mid=(l+r)/2;
    if(l<=x&&x<=mid)return qu(nod*2,l,mid,x);
    return qu(nod*2+1,mid+1,r,x);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    scanf("%lld",&n);
    scanf("%lld",&q);
    scanf("%lld",&s);
    scanf("%lld",&t);
    long long b;
    scanf("%lld",&b);
    up(1,0,n,0,0,b);
    for(int i=0;i<n;i++)
    {
        long long a;
        scanf("%lld",&a);
        long long dif=b-a;
        if(dif>=0)ans+=dif*t;
        else ans+=dif*s;
        up(1,0,n,i+1,i+1,a);
        b=a;
    }
    while(q--)
    {
        int l,r;
        long long x;
        scanf("%d",&l);
        scanf("%d",&r);
        scanf("%lld",&x);
        long long oa=qu(1,0,n,l);
        long long ob=qu(1,0,n,r);
        up(1,0,n,l,r,x);
        long long a=oa+x;
        long long b=ob+x;
        long long c=qu(1,0,n,l-1);
        long long d=qu(1,0,n,r+1);
        if(l>0)
        {
            long long dif=c-oa;
            if(dif>=0)ans-=dif*t;
            else ans-=dif*s;
            dif=c-a;
            if(dif>=0)ans+=dif*t;
            else ans+=dif*s;
        }
        if(r<n)
        {
            long long dif=ob-d;
            if(dif>=0)ans-=dif*t;
            else ans-=dif*s;
            dif=b-d;
            if(dif>=0)ans+=dif*t;
            else ans+=dif*s;
        }
        cout<<ans<<endl;
    }
}

Compilation message (stderr)

foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:58:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld",&n);
     ~~~~~^~~~~~~~~~~
foehn_phenomena.cpp:59:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld",&q);
     ~~~~~^~~~~~~~~~~
foehn_phenomena.cpp:60:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld",&s);
     ~~~~~^~~~~~~~~~~
foehn_phenomena.cpp:61:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld",&t);
     ~~~~~^~~~~~~~~~~
foehn_phenomena.cpp:63:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld",&b);
     ~~~~~^~~~~~~~~~~
foehn_phenomena.cpp:68:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld",&a);
         ~~~~~^~~~~~~~~~~
foehn_phenomena.cpp:79:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&l);
         ~~~~~^~~~~~~~~
foehn_phenomena.cpp:80:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&r);
         ~~~~~^~~~~~~~~
foehn_phenomena.cpp:81:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld",&x);
         ~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...