답안 #706146

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
706146 2023-03-06T01:32:13 Z pcc Snowball (JOI21_ho_t2) C++14
100 / 100
100 ms 11956 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<ll,ll>
#define fs first
#define sc second

const ll mxn = 2e5+10;
const ll inf = 1e18;
ll arr[mxn];
ll req[mxn];
pll maxi[mxn];
bool isl[mxn];
ll ans[mxn];
ll n,q;

ll calc(ll len){
    ll l = 0,r = q;
    while(l != r){
        ll mid = (l+r+1)>>1;
        if(maxi[mid].sc-maxi[mid].fs>len)r = mid-1;
        else l = mid;
    }
    if(r >= q)return q;
    else return l;
}

int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n>>q;
    arr[0] = -inf,arr[n+1] = inf;
    for(int i = 1;i<=n;i++)cin>>arr[i];
    ll now = 0;
    for(int i = 1;i<=q;i++){
        cin>>req[i];
        if(req[i]==0){
            q--;
            i--;
            continue;
        }
        maxi[i] = maxi[i-1];
        now += req[i];
        if(maxi[i].fs>now)isl[i] = true;
        if(maxi[i].sc<now)isl[i] = false;
        maxi[i].fs = min(maxi[i].fs,now);
        maxi[i].sc = max(maxi[i].sc,now);
    }
    for(int i = 1;i<=n+1;i++){
        auto re = calc(arr[i]-arr[i-1]);
        ans[i-1] += maxi[re].sc;
        ans[i] -= maxi[re].fs;
        if(re != q&&!isl[re+1])ans[i-1] += (arr[i]-arr[i-1])-(maxi[re].sc-maxi[re].fs);
        else if(re != q&&isl[re+1])ans[i] += (arr[i]-arr[i-1])-(maxi[re].sc-maxi[re].fs);
    }
    for(int i = 1;i<=n;i++)cout<<ans[i]<<'\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 376 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 0 ms 328 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 376 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 0 ms 328 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 32 ms 7052 KB Output is correct
21 Correct 25 ms 7116 KB Output is correct
22 Correct 24 ms 6832 KB Output is correct
23 Correct 25 ms 6824 KB Output is correct
24 Correct 31 ms 7188 KB Output is correct
25 Correct 100 ms 11760 KB Output is correct
26 Correct 98 ms 11724 KB Output is correct
27 Correct 88 ms 11344 KB Output is correct
28 Correct 97 ms 11192 KB Output is correct
29 Correct 97 ms 10100 KB Output is correct
30 Correct 80 ms 8524 KB Output is correct
31 Correct 60 ms 7876 KB Output is correct
32 Correct 55 ms 6852 KB Output is correct
33 Correct 10 ms 1732 KB Output is correct
34 Correct 92 ms 11792 KB Output is correct
35 Correct 92 ms 11596 KB Output is correct
36 Correct 95 ms 11812 KB Output is correct
37 Correct 98 ms 11640 KB Output is correct
38 Correct 97 ms 11404 KB Output is correct
39 Correct 90 ms 11316 KB Output is correct
40 Correct 72 ms 11312 KB Output is correct
41 Correct 29 ms 7092 KB Output is correct
42 Correct 64 ms 5732 KB Output is correct
43 Correct 75 ms 11828 KB Output is correct
44 Correct 28 ms 7072 KB Output is correct
45 Correct 79 ms 11364 KB Output is correct
46 Correct 79 ms 11908 KB Output is correct
47 Correct 76 ms 11848 KB Output is correct
48 Correct 83 ms 11956 KB Output is correct