Submission #536191

# Submission time Handle Problem Language Result Execution time Memory
536191 2022-03-12T14:59:26 Z groshi Foehn Phenomena (JOI17_foehn_phenomena) C++17
100 / 100
212 ms 14688 KB
#include<iostream>

using namespace std;
int pot=1;
long long drzewo[500000];
long long a[300000];
void dodaj(int x,int y,long long ile)
{
    x+=pot;
    y+=pot;
    drzewo[x]+=ile;
    if(x!=y)
        drzewo[y]+=ile;
    while(x/2!=y/2)
    {
        if(x%2==0)
            drzewo[x+1]+=ile;
        if(y%2==1)
            drzewo[y-1]+=ile;
        x/=2;
        y/=2;
    }
}
long long zap(int x)
{
    x+=pot;
    long long wynik=0;
    wynik+=drzewo[x];
    x/=2;
    while(x>0)
    {
        wynik+=drzewo[x];
        x/=2;
    }
    return wynik;
}
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    long long n,q,s,t,x,y,z;
    cin>>n>>q>>s>>t;
    for(int i=1;i<=n+1;i++)
        cin>>a[i];
    while(pot<=n)
        pot*=2;
    pot--;
    for(int i=1;i<=n+1;i++)
        drzewo[i+pot]=a[i];
    long long wynik=0;
    for(int i=2;i<=n+1;i++)
    {
        if(a[i]>a[i-1])
            wynik-=(a[i]-a[i-1])*s;
        else wynik+=(a[i-1]-a[i])*t;
    }
    while(q--)
    {
        cin>>x>>y>>z;
        x++;
        y++;
        dodaj(x,y,z);
        long long nowy_x=zap(x);
        long long nowy_y=zap(y);
        //if(x>1)
        //{
            long long x_1=zap(x-1);
            long long stary_x=nowy_x-z;
            if(stary_x>x_1)
                wynik+=(stary_x-x_1)*s;
            else wynik-=(x_1-stary_x)*t;
            if(nowy_x>x_1)
                wynik-=(nowy_x-x_1)*s;
            else wynik+=(x_1-nowy_x)*t;
        //}
        if(y<n+1)
        {
            long long y_1=zap(y+1);
            long long stary_y=nowy_y-z;
            if(y_1>stary_y)
                wynik+=(y_1-stary_y)*s;
            else wynik-=(stary_y-y_1)*t;
            if(y_1>nowy_y)
                wynik-=(y_1-nowy_y)*s;
            else wynik+=(nowy_y-y_1)*t;
        }
        cout<<wynik<<"\n";
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 472 KB Output is correct
6 Correct 3 ms 388 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 472 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 472 KB Output is correct
13 Correct 2 ms 344 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 3 ms 380 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 3 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 166 ms 6424 KB Output is correct
2 Correct 157 ms 7084 KB Output is correct
3 Correct 137 ms 7596 KB Output is correct
4 Correct 145 ms 12464 KB Output is correct
5 Correct 189 ms 13600 KB Output is correct
6 Correct 106 ms 11084 KB Output is correct
7 Correct 109 ms 11068 KB Output is correct
8 Correct 149 ms 13348 KB Output is correct
9 Correct 161 ms 13764 KB Output is correct
10 Correct 140 ms 12516 KB Output is correct
11 Correct 102 ms 10872 KB Output is correct
12 Correct 127 ms 11652 KB Output is correct
13 Correct 105 ms 11944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 472 KB Output is correct
6 Correct 3 ms 388 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 472 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 472 KB Output is correct
13 Correct 2 ms 344 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 3 ms 380 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 3 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 166 ms 6424 KB Output is correct
23 Correct 157 ms 7084 KB Output is correct
24 Correct 137 ms 7596 KB Output is correct
25 Correct 145 ms 12464 KB Output is correct
26 Correct 189 ms 13600 KB Output is correct
27 Correct 106 ms 11084 KB Output is correct
28 Correct 109 ms 11068 KB Output is correct
29 Correct 149 ms 13348 KB Output is correct
30 Correct 161 ms 13764 KB Output is correct
31 Correct 140 ms 12516 KB Output is correct
32 Correct 102 ms 10872 KB Output is correct
33 Correct 127 ms 11652 KB Output is correct
34 Correct 105 ms 11944 KB Output is correct
35 Correct 182 ms 11992 KB Output is correct
36 Correct 176 ms 13440 KB Output is correct
37 Correct 161 ms 14388 KB Output is correct
38 Correct 185 ms 14060 KB Output is correct
39 Correct 158 ms 13964 KB Output is correct
40 Correct 187 ms 14024 KB Output is correct
41 Correct 166 ms 13880 KB Output is correct
42 Correct 195 ms 13988 KB Output is correct
43 Correct 155 ms 13204 KB Output is correct
44 Correct 212 ms 13628 KB Output is correct
45 Correct 152 ms 13644 KB Output is correct
46 Correct 167 ms 14688 KB Output is correct
47 Correct 122 ms 11672 KB Output is correct
48 Correct 115 ms 11616 KB Output is correct
49 Correct 141 ms 12364 KB Output is correct
50 Correct 102 ms 11468 KB Output is correct
51 Correct 145 ms 11924 KB Output is correct
52 Correct 103 ms 11684 KB Output is correct