Submission #224195

#TimeUsernameProblemLanguageResultExecution timeMemory
224195Ruxandra985Foehn Phenomena (JOI17_foehn_phenomena)C++14
0 / 100
385 ms10616 KiB
#include <bits/stdc++.h>

using namespace std;

int aint[800010] , v[200010];

void build (int nod , int st , int dr){
    int mid = (st + dr)/2;

    if (st == dr){
        aint[nod] = v[st];
        return;
    }

    build (2 * nod , st , mid);
    build (2 * nod + 1 , mid + 1 , dr);

}

void update (int nod , int st , int dr , int l , int r , int val){
    int mid = (st + dr)/2;

    if (l <= st && dr <= r){
        aint[nod] += val;
        return;
    }

    aint[2 * nod] += aint[nod];
    aint[2 * nod + 1] += aint[nod];

    aint[nod] = 0;

    if (l <= mid)
        update (2 * nod , st , mid , l , r , val);
    if (mid + 1 <= r)
        update (2 * nod + 1 , mid + 1 , dr , l , r , val);


}

int query (int nod , int st , int dr , int p){

    int mid = (st + dr)/2;

    if (st == dr){
        return aint[nod];
    }

    aint[2 * nod] += aint[nod];
    aint[2 * nod + 1] += aint[nod];

    aint[nod] = 0;

    if (p <= mid)
        return query (2 * nod , st , mid , p);
    else
        return query (2 * nod + 1 , mid + 1 , dr , p);


}

int main()
{
    FILE *fin = stdin;
    FILE *fout = stdout;
    int n , i , q , s , t , sol , p1 , p2 , q1 , q2 , l , r , x;
    fscanf (fin,"%d%d%d%d",&n,&q,&s,&t);
    /// temp scade cu s / unitate cand alt creste
    /// temp creste cu t / unitate cand alt scade

    for (i = 0 ; i <= n ; i++){
        fscanf (fin,"%d",&v[i]);
    }

    build (1 , 0 , n);

    sol = 0;

    for (i = 0 ; i < n ; i++){
        if (v[i] < v[i + 1])
            sol = sol - s * (v[i + 1] - v[i]);
        else sol = sol + t * (v[i] - v[i + 1]);
    }

    for (;q;q--){
        fscanf (fin,"%d%d%d",&l,&r,&x);

        p1 = query (1 , 0 , n , l - 1);
        p2 = query (1 , 0 , n , l);

        if (p1 < p2)
            sol = sol + s * (p2 - p1);
        else sol = sol - t * (p1 - p2);

        q1 = query (1 , 0 , n , r);
        q2 = query (1 , 0 , n , r + 1);

        if (r != n){

            if (q1 < q2)
                sol = sol + s * (q2 - q1);
            else sol = sol - t * (q1 - q2);

        }

        update (1 , 0 , n , l , r , x);

        p2 += x;
        q1 += x;

        if (p1 < p2)
            sol = sol - s * (p2 - p1);
        else sol = sol + t * (p1 - p2);


        if (r != n){

            if (q1 < q2)
                sol = sol - s * (q2 - q1);
            else sol = sol + t * (q1 - q2);

        }


        fprintf (fout,"%d\n",sol);

    }

    return 0;
}

Compilation message (stderr)

foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:67:12: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     fscanf (fin,"%d%d%d%d",&n,&q,&s,&t);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:72:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         fscanf (fin,"%d",&v[i]);
         ~~~~~~~^~~~~~~~~~~~~~~~
foehn_phenomena.cpp:86:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         fscanf (fin,"%d%d%d",&l,&r,&x);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...