답안 #373941

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
373941 2021-03-06T08:16:25 Z achibasadzishvili Snowball (JOI21_ho_t2) C++17
100 / 100
258 ms 17772 KB
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
using namespace std;
ll n,q,ans[500005],a[500005];
set<pair<ll,ll> >st;
int main(){
    ios::sync_with_stdio(false);
    cin >> n >> q;
    
    for(int i=1; i<=n; i++){
        cin >> a[i];
        if(i >= 2){
            st.insert(mp(a[i] - a[i - 1] , i));
        }
    }
    ll mn = 0 , mx = 0 , cur = 0;
    while(q--){
        ll x;
        cin >> x;
        cur += x;
        ll bef = cur;
        mx = max(mx , cur);
        mn = min(mn , cur);
        while(st.size() && abs(mx) + abs(mn) >= (*st.begin()).f){
            ll i = (*st.begin()).s;
            st.erase(st.begin());
            if(bef == mx){
                ans[i] += abs(mn);
                ans[i - 1] += a[i] - a[i - 1] - abs(mn);
            }
            else {
                ans[i - 1] += mx;
                ans[i] += a[i] - a[i - 1] - mx;
            }
        }
    }
    
    while(st.size()){
        ll i = (*st.begin()).s;
        st.erase(st.begin());
        ans[i] += abs(mn);
        ans[i - 1] += mx;
    }
    ans[1] += abs(mn);
    ans[n] += abs(mx);
    
    for(int i=1; i<=n; i++)
        cout << ans[i] << '\n';
    
    
    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 2 ms 492 KB Output is correct
6 Correct 2 ms 492 KB Output is correct
7 Correct 2 ms 492 KB Output is correct
8 Correct 2 ms 492 KB Output is correct
9 Correct 2 ms 492 KB Output is correct
10 Correct 2 ms 492 KB Output is correct
11 Correct 2 ms 492 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 2 ms 492 KB Output is correct
16 Correct 2 ms 492 KB Output is correct
17 Correct 2 ms 568 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 2 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 2 ms 492 KB Output is correct
6 Correct 2 ms 492 KB Output is correct
7 Correct 2 ms 492 KB Output is correct
8 Correct 2 ms 492 KB Output is correct
9 Correct 2 ms 492 KB Output is correct
10 Correct 2 ms 492 KB Output is correct
11 Correct 2 ms 492 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 2 ms 492 KB Output is correct
16 Correct 2 ms 492 KB Output is correct
17 Correct 2 ms 568 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 2 ms 492 KB Output is correct
20 Correct 31 ms 364 KB Output is correct
21 Correct 28 ms 364 KB Output is correct
22 Correct 27 ms 364 KB Output is correct
23 Correct 27 ms 492 KB Output is correct
24 Correct 35 ms 2060 KB Output is correct
25 Correct 245 ms 17692 KB Output is correct
26 Correct 239 ms 17640 KB Output is correct
27 Correct 227 ms 17388 KB Output is correct
28 Correct 225 ms 17388 KB Output is correct
29 Correct 212 ms 17260 KB Output is correct
30 Correct 188 ms 16876 KB Output is correct
31 Correct 125 ms 16492 KB Output is correct
32 Correct 121 ms 16364 KB Output is correct
33 Correct 19 ms 2156 KB Output is correct
34 Correct 224 ms 17644 KB Output is correct
35 Correct 248 ms 17388 KB Output is correct
36 Correct 258 ms 17644 KB Output is correct
37 Correct 234 ms 17388 KB Output is correct
38 Correct 209 ms 17388 KB Output is correct
39 Correct 190 ms 17644 KB Output is correct
40 Correct 140 ms 17516 KB Output is correct
41 Correct 30 ms 492 KB Output is correct
42 Correct 199 ms 16364 KB Output is correct
43 Correct 137 ms 17644 KB Output is correct
44 Correct 34 ms 492 KB Output is correct
45 Correct 242 ms 17472 KB Output is correct
46 Correct 158 ms 17772 KB Output is correct
47 Correct 151 ms 17772 KB Output is correct
48 Correct 156 ms 17772 KB Output is correct