답안 #838905

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
838905 2023-08-28T08:47:23 Z LeVanThuc Snowball (JOI21_ho_t2) C++17
100 / 100
71 ms 13880 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define p(x,y) pair<ll,ll>(x,y)
#define BIT(i,x) ((x>>i)&1)
#define MASK(x) (1<<x)
#define ld long double
#define __builtin_popcount __builtin_popcountll
#define pll pair<ll,ll>
template<class T1,class T2>
bool maximize(T1 &x,const T2 &y)
{
    if(x<y)
    {
        x=y;
        return 1;
    }
    return 0;
}
template<class T1,class T2>
bool minimize(T1 &x,const T2 &y)
{
    if(x>y)
    {
        x=y;
        return 1;
    }
    return 0;
}
void online()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
#ifdef thuc
    freopen("input.INP","r",stdin);
    freopen("output.OUT","w",stdout);
#endif
}

const ll N=2e5+10,M=998244353;
ll a[N],n,ans[N];
int main()
{
    online();
    vector<pll> vt;
    ll q;
    cin>>n>>q;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(i>1) vt.emplace_back(a[i]-a[i-1],i);
    }
    vt.emplace_back(1e18,1);
    vt.emplace_back(1e18,n+1);
    sort(vt.begin(),vt.end(),greater<pll>());
//    for(auto [x,y]:vt) cout<<x<<' '<<y<<'\n';
    ll mx=0,mn=0,cr=0;
    while(q--)
    {
        ll x;
        cin>>x;
        cr+=x;
        if(minimize(mn,cr))
        {
            while(vt.back().fi<=(mx-mn))
            {
                ll k=vt.back().se;
                ans[k-1]+=mx;
                ll z=vt.back().fi-mx;
                ans[k]+=z;
                vt.pop_back();
            }
        }
        if(maximize(mx,cr))
        {
            while(vt.back().fi<=(mx-mn))
            {
                ll k=vt.back().se;
                ans[k]-=mn;
                ll z=vt.back().fi+mn;
                ans[k-1]+=z;
                vt.pop_back();
            }
        }
    }
    while(vt.size())
    {
        ll k=vt.back().se;
        ans[k]-=mn;
        ans[k-1]+=mx;
        vt.pop_back();
    }
    for(int i=1;i<=n;i++)
    {
        cout<<ans[i]<<'\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 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 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 212 KB Output is correct
13 Correct 0 ms 212 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 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 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 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 212 KB Output is correct
13 Correct 0 ms 212 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 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 17 ms 212 KB Output is correct
21 Correct 16 ms 212 KB Output is correct
22 Correct 16 ms 340 KB Output is correct
23 Correct 16 ms 424 KB Output is correct
24 Correct 19 ms 1236 KB Output is correct
25 Correct 61 ms 8244 KB Output is correct
26 Correct 60 ms 8232 KB Output is correct
27 Correct 61 ms 7992 KB Output is correct
28 Correct 61 ms 8100 KB Output is correct
29 Correct 61 ms 7892 KB Output is correct
30 Correct 56 ms 7452 KB Output is correct
31 Correct 54 ms 7096 KB Output is correct
32 Correct 41 ms 7092 KB Output is correct
33 Correct 6 ms 1236 KB Output is correct
34 Correct 61 ms 8248 KB Output is correct
35 Correct 58 ms 8084 KB Output is correct
36 Correct 60 ms 8252 KB Output is correct
37 Correct 60 ms 8020 KB Output is correct
38 Correct 65 ms 7992 KB Output is correct
39 Correct 62 ms 8120 KB Output is correct
40 Correct 65 ms 7988 KB Output is correct
41 Correct 20 ms 2640 KB Output is correct
42 Correct 55 ms 10224 KB Output is correct
43 Correct 67 ms 13480 KB Output is correct
44 Correct 19 ms 2892 KB Output is correct
45 Correct 62 ms 11668 KB Output is correct
46 Correct 71 ms 13752 KB Output is correct
47 Correct 60 ms 13856 KB Output is correct
48 Correct 58 ms 13880 KB Output is correct