Submission #974293

# Submission time Handle Problem Language Result Execution time Memory
974293 2024-05-03T07:36:47 Z berr Snowball (JOI21_ho_t2) C++17
100 / 100
121 ms 17132 KB
#include <bits/stdc++.h>
using namespace std; 
#define int long long

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
   
    int n, q; cin >> n >> q;

    vector<int> x(n), l(n), r(n);
    vector<int> mi(q+1), ma(q+1);
    for(auto &i: x) cin >> i;
    vector<int> op(q+1);

    for(int i=1; i<=q; i++) cin >> op[i];

    for(int i=1; i<=q; i++){
        op[i]+=op[i-1];
        mi[i]=mi[i-1]; ma[i] =ma[i-1];

        if(op[i] < op[mi[i]]) mi[i]=i;
        if(op[i] > op[ma[i]]) ma[i]=i;
    }

    l[0]=x[0]+op[mi[q]]; r[n-1] = x[n-1]+op[ma[q]];

    for(int i=0; i<n-1; i++){
        int s=-1;

        for(int l=20; l>=0; l--){
            int tmp = s+(1<<l);
            if(tmp >= q) continue;
            if((x[i]+op[ma[tmp]]>=x[i+1]+op[mi[tmp]])) continue;
            s=tmp;
        }

        s++;

        if(x[i]+op[ma[s]]>=x[i+1]+op[mi[s]]){            
            if(ma[s] < mi[s]){
                r[i]=x[i]+op[ma[s]];
                l[i+1]=r[i];
            }
            else{
                l[i+1]=x[i+1]+op[mi[s]];
                r[i]=l[i+1];

            }
        }
        else{

            r[i]=min(x[i+1]+op[mi[s]], x[i]+op[ma[s]]);
            l[i+1]=max(x[i+1]+op[mi[s]], x[i]+op[ma[s]]);
        }
    }

  

    for(int i=0; i<n; i++) cout<<r[i]-l[i]<<"\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 392 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 464 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 1 ms 856 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 392 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 464 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 1 ms 856 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 22 ms 7260 KB Output is correct
21 Correct 21 ms 6948 KB Output is correct
22 Correct 21 ms 6872 KB Output is correct
23 Correct 20 ms 6748 KB Output is correct
24 Correct 28 ms 7252 KB Output is correct
25 Correct 121 ms 15124 KB Output is correct
26 Correct 118 ms 14928 KB Output is correct
27 Correct 114 ms 14676 KB Output is correct
28 Correct 115 ms 14816 KB Output is correct
29 Correct 119 ms 14256 KB Output is correct
30 Correct 92 ms 13784 KB Output is correct
31 Correct 68 ms 13108 KB Output is correct
32 Correct 62 ms 13276 KB Output is correct
33 Correct 8 ms 1884 KB Output is correct
34 Correct 108 ms 15444 KB Output is correct
35 Correct 107 ms 14816 KB Output is correct
36 Correct 120 ms 14932 KB Output is correct
37 Correct 114 ms 14928 KB Output is correct
38 Correct 112 ms 14648 KB Output is correct
39 Correct 109 ms 14956 KB Output is correct
40 Correct 94 ms 14792 KB Output is correct
41 Correct 23 ms 7768 KB Output is correct
42 Correct 47 ms 13140 KB Output is correct
43 Correct 80 ms 16592 KB Output is correct
44 Correct 22 ms 7764 KB Output is correct
45 Correct 54 ms 14680 KB Output is correct
46 Correct 84 ms 16648 KB Output is correct
47 Correct 83 ms 17132 KB Output is correct
48 Correct 85 ms 17072 KB Output is correct