답안 #553589

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
553589 2022-04-26T10:02:43 Z andrei_boaca Snowball (JOI21_ho_t2) C++14
100 / 100
1578 ms 15324 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll INF=1e17;
ll n,q,x[200005],w[200005],smax[200005],smin[200005],sol[200005];
ll getfst(ll need)
{
    assert(need!=0);
    if(need>0)
    {
        ll st=1;
        ll dr=q;
        ll poz=INF;
        while(st<=dr)
        {
            ll mij=(st+dr)/2;
            if(smax[mij]>=need)
            {
                poz=min(poz,mij);
                dr=mij-1;
            }
            else
                st=mij+1;
        }
        return poz;
    }
    else
    {
        ll st=1;
        ll dr=q;
        ll poz=INF;
        while(st<=dr)
        {
            ll mij=(st+dr)/2;
            if(smin[mij]<=need)
            {
                poz=min(poz,mij);
                dr=mij-1;
            }
            else
                st=mij+1;
        }
        return poz;
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>q;
    for(ll i=1;i<=n;i++)
        cin>>x[i];
    sort(x+1,x+n+1);
    for(ll i=1;i<=q;i++)
        cin>>w[i];
    smax[1]=w[1];
    smin[1]=w[1];
    for(ll i=2;i<=q;i++)
    {
        w[i]=w[i-1]+w[i];
        smax[i]=max(smax[i-1],w[i]);
        smin[i]=min(smin[i-1],w[i]);
    }
    for(ll i=1;i<n;i++)
    {
        ll p1=x[i];
        ll p2=x[i+1];
        ll st=p1+1;
        ll dr=p2;
        ll nr=0;
        while(st<=dr)
        {
            ll mij=(st+dr)/2;
            ll needL=mij-p1;
            ll needR=(mij-1)-p2;
            ll fstL=getfst(needL);
            ll fstR=getfst(needR);
            assert(fstL!=fstR||(fstL==INF||fstR==INF));
            if(fstL<fstR&&fstL<=q)
            {
                nr=mij-p1;
                st=mij+1;
            }
            else
                dr=mij-1;
        }
        sol[i]+=nr;
        st=p1;
        dr=p2-1;
        nr=0;
        while(st<=dr)
        {
            ll mij=(st+dr)/2;
            ll needL=mij+1-p1;
            ll needR=mij-p2;
            ll fstL=getfst(needL);
            ll fstR=getfst(needR);
            assert(fstL!=fstR||(fstL==INF||fstR==INF));
            if(fstR<fstL&&fstR<=q)
            {
                nr=p2-mij;
                dr=mij-1;
            }
            else
                st=mij+1;
        }
        sol[i+1]+=nr;
    }
    if(smin[q]<0)
        sol[1]-=smin[q];
    if(smax[q]>0)
        sol[n]+=smax[q];
    for(ll i=1;i<=n;i++)
        cout<<sol[i]<<'\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 10 ms 420 KB Output is correct
5 Correct 8 ms 424 KB Output is correct
6 Correct 8 ms 340 KB Output is correct
7 Correct 7 ms 340 KB Output is correct
8 Correct 6 ms 340 KB Output is correct
9 Correct 5 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 10 ms 420 KB Output is correct
16 Correct 11 ms 432 KB Output is correct
17 Correct 6 ms 424 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 2 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 2 ms 340 KB Output is correct
4 Correct 10 ms 420 KB Output is correct
5 Correct 8 ms 424 KB Output is correct
6 Correct 8 ms 340 KB Output is correct
7 Correct 7 ms 340 KB Output is correct
8 Correct 6 ms 340 KB Output is correct
9 Correct 5 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 10 ms 420 KB Output is correct
16 Correct 11 ms 432 KB Output is correct
17 Correct 6 ms 424 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 25 ms 4988 KB Output is correct
21 Correct 33 ms 5032 KB Output is correct
22 Correct 27 ms 5036 KB Output is correct
23 Correct 39 ms 4960 KB Output is correct
24 Correct 184 ms 5480 KB Output is correct
25 Correct 1578 ms 9924 KB Output is correct
26 Correct 1530 ms 9632 KB Output is correct
27 Correct 1433 ms 9744 KB Output is correct
28 Correct 1425 ms 9516 KB Output is correct
29 Correct 1319 ms 9280 KB Output is correct
30 Correct 782 ms 8824 KB Output is correct
31 Correct 111 ms 8584 KB Output is correct
32 Correct 66 ms 8496 KB Output is correct
33 Correct 129 ms 1276 KB Output is correct
34 Correct 1413 ms 9740 KB Output is correct
35 Correct 1384 ms 9632 KB Output is correct
36 Correct 1555 ms 9620 KB Output is correct
37 Correct 1477 ms 9440 KB Output is correct
38 Correct 1450 ms 9532 KB Output is correct
39 Correct 1477 ms 9456 KB Output is correct
40 Correct 768 ms 9620 KB Output is correct
41 Correct 26 ms 4932 KB Output is correct
42 Correct 277 ms 11544 KB Output is correct
43 Correct 512 ms 14920 KB Output is correct
44 Correct 31 ms 7584 KB Output is correct
45 Correct 662 ms 13132 KB Output is correct
46 Correct 678 ms 15068 KB Output is correct
47 Correct 547 ms 15324 KB Output is correct
48 Correct 462 ms 15308 KB Output is correct