Submission #51005

# Submission time Handle Problem Language Result Execution time Memory
51005 2018-06-15T14:38:57 Z Diuven Foehn Phenomena (JOI17_foehn_phenomena) C++11
100 / 100
242 ms 168092 KB
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long lld;
const int MX=200010, inf=2e9;

int n, q, s, t;
lld now;
lld tree[MX];

void upt(int r, int val){
    for(; r>0; r-=r&(-r))
        tree[r]+=val;
}
void upt(int l, int r, int x){
    upt(r,x); upt(l-1, -x);
}
lld val(int pos){
    lld ans=0;
    for(; 0<pos && pos<=n; pos+=pos&(-pos))
        ans+=tree[pos];
    return ans;
}

inline lld f(lld a, lld b){
    return (a-b) * (a>b ? t : s);
}

void debug(){
    return;
    cout<<"DEBUG!!\n";
    for(int i=1; i<=n; i++) cout<<val(i)<<' ';
    cout<<'\n';
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    cin>>n>>q>>s>>t;
    for(int i=0; i<=n; i++){
        int h; cin>>h;
        upt(i,i,h);
        lld prv=val(i-1);
        now += f(prv, h);
        debug();
    }
    for(int i=1; i<=q; i++){
        int l, r, x;
        cin>>l>>r>>x;
        lld ll = val(l-1), rr = val(r+1);
        lld lr1 = val(l), rl1 = val(r);
        upt(l,r,x);
        lld lr2 = val(l), rl2 = val(r);
        if(r<n) now += f(rl2, rr) - f(rl1, rr);
        now += f(ll, lr2) - f(ll, lr1);
        cout<<now<<'\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 4 ms 684 KB Output is correct
3 Correct 4 ms 736 KB Output is correct
4 Correct 3 ms 800 KB Output is correct
5 Correct 4 ms 800 KB Output is correct
6 Correct 4 ms 992 KB Output is correct
7 Correct 4 ms 992 KB Output is correct
8 Correct 3 ms 1108 KB Output is correct
9 Correct 4 ms 1108 KB Output is correct
10 Correct 4 ms 1164 KB Output is correct
11 Correct 4 ms 1228 KB Output is correct
12 Correct 4 ms 1288 KB Output is correct
13 Correct 5 ms 1292 KB Output is correct
14 Correct 5 ms 1340 KB Output is correct
15 Correct 3 ms 1512 KB Output is correct
16 Correct 3 ms 1512 KB Output is correct
17 Correct 3 ms 1644 KB Output is correct
18 Correct 3 ms 1644 KB Output is correct
19 Correct 2 ms 1644 KB Output is correct
20 Correct 2 ms 1644 KB Output is correct
21 Correct 2 ms 1644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 201 ms 9988 KB Output is correct
2 Correct 222 ms 16064 KB Output is correct
3 Correct 227 ms 22176 KB Output is correct
4 Correct 203 ms 26868 KB Output is correct
5 Correct 203 ms 33680 KB Output is correct
6 Correct 144 ms 38844 KB Output is correct
7 Correct 145 ms 43324 KB Output is correct
8 Correct 210 ms 48784 KB Output is correct
9 Correct 211 ms 54688 KB Output is correct
10 Correct 197 ms 58900 KB Output is correct
11 Correct 157 ms 64408 KB Output is correct
12 Correct 171 ms 69752 KB Output is correct
13 Correct 156 ms 74712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 4 ms 684 KB Output is correct
3 Correct 4 ms 736 KB Output is correct
4 Correct 3 ms 800 KB Output is correct
5 Correct 4 ms 800 KB Output is correct
6 Correct 4 ms 992 KB Output is correct
7 Correct 4 ms 992 KB Output is correct
8 Correct 3 ms 1108 KB Output is correct
9 Correct 4 ms 1108 KB Output is correct
10 Correct 4 ms 1164 KB Output is correct
11 Correct 4 ms 1228 KB Output is correct
12 Correct 4 ms 1288 KB Output is correct
13 Correct 5 ms 1292 KB Output is correct
14 Correct 5 ms 1340 KB Output is correct
15 Correct 3 ms 1512 KB Output is correct
16 Correct 3 ms 1512 KB Output is correct
17 Correct 3 ms 1644 KB Output is correct
18 Correct 3 ms 1644 KB Output is correct
19 Correct 2 ms 1644 KB Output is correct
20 Correct 2 ms 1644 KB Output is correct
21 Correct 2 ms 1644 KB Output is correct
22 Correct 201 ms 9988 KB Output is correct
23 Correct 222 ms 16064 KB Output is correct
24 Correct 227 ms 22176 KB Output is correct
25 Correct 203 ms 26868 KB Output is correct
26 Correct 203 ms 33680 KB Output is correct
27 Correct 144 ms 38844 KB Output is correct
28 Correct 145 ms 43324 KB Output is correct
29 Correct 210 ms 48784 KB Output is correct
30 Correct 211 ms 54688 KB Output is correct
31 Correct 197 ms 58900 KB Output is correct
32 Correct 157 ms 64408 KB Output is correct
33 Correct 171 ms 69752 KB Output is correct
34 Correct 156 ms 74712 KB Output is correct
35 Correct 211 ms 77952 KB Output is correct
36 Correct 219 ms 84812 KB Output is correct
37 Correct 216 ms 90956 KB Output is correct
38 Correct 219 ms 96288 KB Output is correct
39 Correct 214 ms 101616 KB Output is correct
40 Correct 223 ms 107100 KB Output is correct
41 Correct 226 ms 112244 KB Output is correct
42 Correct 242 ms 117816 KB Output is correct
43 Correct 218 ms 122468 KB Output is correct
44 Correct 211 ms 128360 KB Output is correct
45 Correct 225 ms 133888 KB Output is correct
46 Correct 231 ms 140452 KB Output is correct
47 Correct 168 ms 145132 KB Output is correct
48 Correct 174 ms 149764 KB Output is correct
49 Correct 194 ms 153396 KB Output is correct
50 Correct 167 ms 158588 KB Output is correct
51 Correct 150 ms 163424 KB Output is correct
52 Correct 147 ms 168092 KB Output is correct