Submission #540378

#TimeUsernameProblemLanguageResultExecution timeMemory
540378krit3379Foehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
352 ms26188 KiB
#include<bits/stdc++.h>
using namespace std;
#define N 200005

struct A{
    long long l,r,up,dow;
};

A t[4*N];
long long a[N],lazy[4*N],s,tt,ll,rr,val;

void push(int x){
    if(lazy[x]){
        if(x*2<4*N){
            lazy[x*2]+=lazy[x];
            t[x*2].l+=lazy[x];
            t[x*2].r+=lazy[x];
        }
        if(x*2+1<4*N){
            lazy[x*2+1]+=lazy[x];
            t[x*2+1].l+=lazy[x];
            t[x*2+1].r+=lazy[x];
        }
        lazy[x]=0;
    }
}

void cre(int x,int l,int r){
    if(l==r){t[x].l=t[x].r=a[l];return ;}
    int mid=(l+r)/2;
    cre(x*2,l,mid);
    cre(x*2+1,mid+1,r);
    t[x].l=t[x*2].l;
    t[x].r=t[x*2+1].r;
    t[x].up=t[x*2].up+t[x*2+1].up;
    t[x].dow=t[x*2].dow+t[x*2+1].dow;
    if(t[x*2].r<t[x*2+1].l)t[x].up+=t[x*2+1].l-t[x*2].r;
    else t[x].dow+=t[x*2].r-t[x*2+1].l;
}

void upd(int x,int l,int r){
    if(l>rr||ll>r)return ;
    if(ll<=l&&r<=rr){
        t[x].l+=val;
        t[x].r+=val;
        lazy[x]+=val;
        return ;
    }
    push(x);
    int mid=(l+r)/2;
    upd(x*2,l,mid);
    upd(x*2+1,mid+1,r);
    t[x].l=t[x*2].l;
    t[x].r=t[x*2+1].r;
    t[x].up=t[x*2].up+t[x*2+1].up;
    t[x].dow=t[x*2].dow+t[x*2+1].dow;
    if(t[x*2].r<t[x*2+1].l)t[x].up+=t[x*2+1].l-t[x*2].r;
    else t[x].dow+=t[x*2].r-t[x*2+1].l;
}

A sol(int x,int l,int r){
    if(l>rr||ll>r)return {(long long)1e18};
    if(ll<=l&&r<=rr)return t[x];
    push(x);
    int mid=(l+r)/2;
    A tl=sol(x*2,l,mid),tr=sol(x*2+1,mid+1,r),tx;
    if(tl.l==1e18)return tr;
    else if(tr.l==1e18)return tl;
    tx.l=tl.l;
    tx.r=tr.r;
    tx.up=tl.up+tr.up;
    tx.dow=tl.dow+tr.dow;
    if(tl.r<tr.l)tx.up+=tr.l-tl.r;
    else tr.dow+=tl.r-tr.l;
}

int main(){
    int n,q,i;
    scanf("%d %d %lld %lld",&n,&q,&s,&tt);
    n++;
    for(i=1;i<=n;i++)scanf("%lld",&a[i]);
    cre(1,1,n);
    while(q--){
        scanf("%d %d %lld",&ll,&rr,&val);
        ll++,rr++;
        upd(1,1,n);
        //A ans=sol(1,1,n);
        A ans=t[1];
        printf("%lld\n",-ans.up*s+ans.dow*tt);
    }
    return 0;
}

Compilation message (stderr)

foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:84:17: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   84 |         scanf("%d %d %lld",&ll,&rr,&val);
      |                ~^          ~~~
      |                 |          |
      |                 int*       long long int*
      |                %lld
foehn_phenomena.cpp:84:20: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'long long int*' [-Wformat=]
   84 |         scanf("%d %d %lld",&ll,&rr,&val);
      |                   ~^           ~~~
      |                    |           |
      |                    int*        long long int*
      |                   %lld
foehn_phenomena.cpp: In function 'A sol(int, int, int)':
foehn_phenomena.cpp:75:1: warning: control reaches end of non-void function [-Wreturn-type]
   75 | }
      | ^
foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:79:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |     scanf("%d %d %lld %lld",&n,&q,&s,&tt);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:81:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |     for(i=1;i<=n;i++)scanf("%lld",&a[i]);
      |                      ~~~~~^~~~~~~~~~~~~~
foehn_phenomena.cpp:84:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   84 |         scanf("%d %d %lld",&ll,&rr,&val);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...