답안 #468187

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
468187 2021-08-27T03:32:28 Z Killer2501 Snowball (JOI21_ho_t2) C++14
33 / 100
199 ms 19736 KB
#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

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);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5068 KB Output is correct
2 Correct 4 ms 5068 KB Output is correct
3 Correct 4 ms 5068 KB Output is correct
4 Correct 5 ms 5160 KB Output is correct
5 Correct 5 ms 5164 KB Output is correct
6 Correct 5 ms 5160 KB Output is correct
7 Correct 5 ms 5160 KB Output is correct
8 Correct 4 ms 5068 KB Output is correct
9 Correct 4 ms 5032 KB Output is correct
10 Correct 4 ms 5068 KB Output is correct
11 Correct 4 ms 5068 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 4 ms 5068 KB Output is correct
15 Correct 4 ms 5196 KB Output is correct
16 Correct 5 ms 5196 KB Output is correct
17 Correct 4 ms 5196 KB Output is correct
18 Correct 3 ms 5020 KB Output is correct
19 Correct 4 ms 5068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5068 KB Output is correct
2 Correct 4 ms 5068 KB Output is correct
3 Correct 4 ms 5068 KB Output is correct
4 Correct 5 ms 5160 KB Output is correct
5 Correct 5 ms 5164 KB Output is correct
6 Correct 5 ms 5160 KB Output is correct
7 Correct 5 ms 5160 KB Output is correct
8 Correct 4 ms 5068 KB Output is correct
9 Correct 4 ms 5032 KB Output is correct
10 Correct 4 ms 5068 KB Output is correct
11 Correct 4 ms 5068 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 4 ms 5068 KB Output is correct
15 Correct 4 ms 5196 KB Output is correct
16 Correct 5 ms 5196 KB Output is correct
17 Correct 4 ms 5196 KB Output is correct
18 Correct 3 ms 5020 KB Output is correct
19 Correct 4 ms 5068 KB Output is correct
20 Correct 41 ms 14932 KB Output is correct
21 Correct 40 ms 14504 KB Output is correct
22 Correct 47 ms 13960 KB Output is correct
23 Correct 37 ms 13844 KB Output is correct
24 Correct 52 ms 14496 KB Output is correct
25 Correct 154 ms 19108 KB Output is correct
26 Correct 199 ms 19736 KB Output is correct
27 Correct 164 ms 18628 KB Output is correct
28 Correct 155 ms 18340 KB Output is correct
29 Correct 147 ms 15412 KB Output is correct
30 Correct 97 ms 12128 KB Output is correct
31 Correct 75 ms 11500 KB Output is correct
32 Correct 84 ms 11588 KB Output is correct
33 Correct 16 ms 6348 KB Output is correct
34 Correct 118 ms 13976 KB Output is correct
35 Correct 122 ms 13848 KB Output is correct
36 Correct 156 ms 19224 KB Output is correct
37 Correct 148 ms 17700 KB Output is correct
38 Correct 153 ms 18820 KB Output is correct
39 Correct 147 ms 18624 KB Output is correct
40 Correct 105 ms 18460 KB Output is correct
41 Incorrect 47 ms 16176 KB Output isn't correct
42 Halted 0 ms 0 KB -