Submission #468187

#TimeUsernameProblemLanguageResultExecution timeMemory
468187Killer2501Snowball (JOI21_ho_t2)C++14
33 / 100
199 ms19736 KiB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define task "tests"
#define pll pair<ll, ll>
#define pi pair<ll, pll>
#define fi first
#define se second

using namespace std;
const ll mod = 1e15+7;
const ll N = 2e5+5;
const int base = 313;
ll n, m, t, k, T, ans, tong, d[N], a[N], b[N], h[N], dp[N], cnt, top[N], nchain[N], chain, par[N];
vector<pll> adj[N];
ll pw(ll k, ll n)
{
    ll total = 1;
    for(; n; n >>= 1)
    {
        if(n & 1)total = total * k % mod;
        k = k * k % mod;
    }
    return total;
}

void sol()
{
    cin >> n >> m;
    for(int i = 1; i <= n; i ++)cin >> a[i];
    vector<ll> l, r;
    vector<pll> vl, vr;
    ll mn = 0, mx = 0;
    for(int i = 1; i <= m; i ++)
    {
        cin >> k;
        b[i] = b[i-1] + k;
        mn = max(mn, -b[i]);
        mx = max(mx, b[i]);
        if(vl.empty() || vl.back().fi < mn)
        {
            vl.pb({mn, mx});
            l.pb(mn+mx);
        }
        if(vr.empty() || vr.back().fi < mx)
        {
            vr.pb({mx, mn});
            r.pb(mn+mx);
        }
        //cout << mn <<" "<<mx<<'\n';
    }
    a[0] = -mod ;
    a[n+1] = mod;
    for(int i = 1; i <= n; i ++)
    {
        ans = 0;
        k = lower_bound(r.begin(), r.end(), a[i+1]-a[i]) - r.begin();
        tong = 0;
        if(k < vr.size())tong = max(tong, a[i+1]-a[i]-vr[k].se);
        if(k)tong = max(tong, vr[k-1].fi);
        ans += tong;
        //cout << tong <<" ";
        k = lower_bound(l.begin(), l.end(), a[i]-a[i-1]) - l.begin();
        tong = 0;
        if(k < vl.size())tong = max(tong, a[i]-a[i-1]-vl[k].se);
        if(k)tong = max(tong, vl[k-1].fi);
        //cout << tong <<" ";
        ans += tong;
        cout << ans << '\n';
    }

}
int main()
{
    if(fopen(task".in", "r"))
    {
       freopen(task".in", "r", stdin);
       freopen(task".out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int ntest = 1;
    //cin >> ntest;
    while(ntest -- > 0)
    sol();
}
/*
5 1
0 1 2
0 2 3
1 3 5
2 4 6
1 1
4 3
*/

Compilation message (stderr)

Main.cpp: In function 'void sol()':
Main.cpp:59:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |         if(k < vr.size())tong = max(tong, a[i+1]-a[i]-vr[k].se);
      |            ~~^~~~~~~~~~~
Main.cpp:65:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |         if(k < vl.size())tong = max(tong, a[i]-a[i-1]-vl[k].se);
      |            ~~^~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:77:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |        freopen(task".in", "r", stdin);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:78:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |        freopen(task".out", "w", stdout);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...