Submission #814640

# Submission time Handle Problem Language Result Execution time Memory
814640 2023-08-08T08:42:20 Z Cookie Snowball (JOI21_ho_t2) C++14
100 / 100
70 ms 13944 KB
#include<bits/stdc++.h>
#include<fstream>
using namespace std;
ifstream fin("FEEDING.INP");
ofstream fout("FEEDING.OUT");
#define sz(a) (int)a.size()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const ld PI = 3.14159265359;
using u128 = __uint128_t;
//const int x[4] = {1, -1, 0, 0};
// int y[4] = {0, 0, 1, -1};
const ll mod = 1e15 + 7, inf = 1e16;
const int mxn = 2e5 + 5;
int n, q;
ll x[mxn + 1], ans[mxn + 1];
signed main()
{
     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> q;
    for(int i = 1; i <= n; i++)cin >> x[i];
    vt<pll>seg;
    for(int i = 1; i < n; i++){
        seg.pb(make_pair(x[i + 1] - x[i], i));
    }
    sort(seg.begin(), seg.end());
    ll mx = 0, mn = 0, p = 0;
    int r = 0;
    for(int i = 1; i <= q; i++){
        ll w; cin >> w; 
        p += w;
        mx = max(mx, p); mn = min(mn, p);
        while(r < sz(seg) && seg[r].first <= mx + abs(mn)){
            int id = seg[r].second;
            if(w < 0){
                ans[id] += mx; ans[id + 1] += (seg[r].first - mx);
            }else{
                ans[id + 1] += abs(mn); ans[id] += (seg[r].first - abs(mn));
            }
            r++;
        }
        
    }
    for(int i = r; i < sz(seg); i++){
        int id = seg[i].second;
        ans[id] += mx; ans[id + 1] += abs(mn);
    }
    ans[n] += mx; ans[1] += abs(mn);
    for(int i = 1; i <= n; i++)cout << ans[i] << "\n";
    return(0);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 268 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 448 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 268 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 448 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 18 ms 340 KB Output is correct
21 Correct 17 ms 340 KB Output is correct
22 Correct 16 ms 352 KB Output is correct
23 Correct 15 ms 340 KB Output is correct
24 Correct 19 ms 1232 KB Output is correct
25 Correct 66 ms 8240 KB Output is correct
26 Correct 63 ms 11860 KB Output is correct
27 Correct 70 ms 11628 KB Output is correct
28 Correct 63 ms 11716 KB Output is correct
29 Correct 62 ms 11292 KB Output is correct
30 Correct 65 ms 10620 KB Output is correct
31 Correct 58 ms 10076 KB Output is correct
32 Correct 45 ms 10192 KB Output is correct
33 Correct 7 ms 1620 KB Output is correct
34 Correct 63 ms 12312 KB Output is correct
35 Correct 60 ms 11724 KB Output is correct
36 Correct 65 ms 11936 KB Output is correct
37 Correct 67 ms 11676 KB Output is correct
38 Correct 64 ms 11572 KB Output is correct
39 Correct 69 ms 11840 KB Output is correct
40 Correct 64 ms 11700 KB Output is correct
41 Correct 19 ms 3144 KB Output is correct
42 Correct 54 ms 10128 KB Output is correct
43 Correct 53 ms 13500 KB Output is correct
44 Correct 19 ms 2880 KB Output is correct
45 Correct 66 ms 11756 KB Output is correct
46 Correct 62 ms 13672 KB Output is correct
47 Correct 61 ms 13812 KB Output is correct
48 Correct 60 ms 13944 KB Output is correct