답안 #1095595

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1095595 2024-10-02T15:55:26 Z vjudge1 Snowball (JOI21_ho_t2) C++17
100 / 100
90 ms 20132 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
const int maxN=2e5+5;
const ll inf=2e18;
int n,q;
pll b[maxN+1];
ll x[maxN+1],a[maxN+1],w[maxN+1],pre1[maxN+1],pre2[maxN+1],sum[maxN+1];
bool check(int k,ll tmp)
{
    return ((pre1[k]+pre2[k])<=tmp);
}
int main()
{
    //freopen("","r",stdin);
    //freopen("","w",stdout);
    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];
    }
    for(int i=1;i<=q;i++)
    {
        cin>>w[i];
    }
    sum[0]=0;
    pre1[0]=pre2[0]=0;
    for(int j=1;j<=q;j++)
    {
        sum[j]=sum[j-1]+w[j];
        pre1[j]=max(pre1[j-1],sum[j]);
        pre2[j]=max(pre2[j-1],-sum[j]);
    }
    a[1]=pre2[q];
    a[n]=pre1[q];
    for(int i=1;i<n;i++)
    {
        ll tmp=x[i+1]-x[i];
        int l=1,r=q,res=0;
        while(l<=r)
        {
            int mid=(l+r)/2;
            if(check(mid,tmp))
            {
                res=mid;
                l=mid+1;
            }
            else r=mid-1;
        }
        if(res>0)
        {
            b[i].fi=pre1[res];
            b[i].se=pre2[res];
        }
        if(res<q)
        {
            ll pre_l=b[i].fi,pre_r=b[i].se;
            ll cur=tmp-pre_l-pre_r;
            if(sum[res+1]>0)
            {
                b[i].fi+=cur;
            }
            else b[i].se+=cur;
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(i<n)
        {
            a[i]+=b[i].fi;
            a[i+1]+=b[i].se;
        }
        cout<<a[i]<<'\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 1 ms 2556 KB Output is correct
6 Correct 1 ms 2648 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2552 KB Output is correct
9 Correct 1 ms 2696 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 1 ms 2556 KB Output is correct
6 Correct 1 ms 2648 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2552 KB Output is correct
9 Correct 1 ms 2696 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2568 KB Output is correct
20 Correct 19 ms 10844 KB Output is correct
21 Correct 17 ms 10716 KB Output is correct
22 Correct 17 ms 10416 KB Output is correct
23 Correct 17 ms 10332 KB Output is correct
24 Correct 20 ms 10824 KB Output is correct
25 Correct 77 ms 18260 KB Output is correct
26 Correct 80 ms 18000 KB Output is correct
27 Correct 90 ms 17748 KB Output is correct
28 Correct 77 ms 18000 KB Output is correct
29 Correct 73 ms 17432 KB Output is correct
30 Correct 63 ms 16720 KB Output is correct
31 Correct 42 ms 16208 KB Output is correct
32 Correct 39 ms 16472 KB Output is correct
33 Correct 7 ms 3928 KB Output is correct
34 Correct 72 ms 18576 KB Output is correct
35 Correct 73 ms 18000 KB Output is correct
36 Correct 73 ms 18256 KB Output is correct
37 Correct 73 ms 18000 KB Output is correct
38 Correct 78 ms 17748 KB Output is correct
39 Correct 64 ms 17848 KB Output is correct
40 Correct 46 ms 18000 KB Output is correct
41 Correct 23 ms 11344 KB Output is correct
42 Correct 47 ms 16424 KB Output is correct
43 Correct 48 ms 19624 KB Output is correct
44 Correct 23 ms 11348 KB Output is correct
45 Correct 45 ms 17984 KB Output is correct
46 Correct 51 ms 19868 KB Output is correct
47 Correct 51 ms 20132 KB Output is correct
48 Correct 57 ms 19992 KB Output is correct