답안 #838904

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
838904 2023-08-28T08:46:41 Z LeVanThuc Snowball (JOI21_ho_t2) C++17
33 / 100
67 ms 8248 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(1e16,1);
    vt.emplace_back(1e16,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 0 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 0 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 17 ms 340 KB Output is correct
21 Correct 17 ms 212 KB Output is correct
22 Correct 17 ms 340 KB Output is correct
23 Correct 15 ms 340 KB Output is correct
24 Correct 19 ms 1220 KB Output is correct
25 Correct 62 ms 8244 KB Output is correct
26 Correct 66 ms 8244 KB Output is correct
27 Correct 61 ms 8116 KB Output is correct
28 Correct 64 ms 7992 KB Output is correct
29 Correct 61 ms 7848 KB Output is correct
30 Correct 58 ms 7396 KB Output is correct
31 Correct 55 ms 7108 KB Output is correct
32 Correct 42 ms 7096 KB Output is correct
33 Correct 7 ms 1236 KB Output is correct
34 Correct 63 ms 8224 KB Output is correct
35 Correct 58 ms 8120 KB Output is correct
36 Correct 61 ms 8248 KB Output is correct
37 Correct 61 ms 8128 KB Output is correct
38 Correct 65 ms 8120 KB Output is correct
39 Correct 67 ms 7992 KB Output is correct
40 Correct 67 ms 8100 KB Output is correct
41 Runtime error 2 ms 724 KB Execution killed with signal 11
42 Halted 0 ms 0 KB -