Submission #378221

# Submission time Handle Problem Language Result Execution time Memory
378221 2021-03-16T09:05:46 Z Atill83 Snowball (JOI21_ho_t2) C++14
100 / 100
263 ms 26476 KB
#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e9+7;
const int MAXN = (int) 3e5+5;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n;
ll x[MAXN];
ll ans[MAXN];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);

    #ifdef Local
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/int.txt","r",stdin);
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/out.txt","w",stdout);
    #endif

    int q;
    cin>>n>>q;


    x[0] = -INF;
    for(int i = 1; i <= n; i++)
        cin>>x[i];

    x[n + 1] = INF;


    ll curdel = 0;

    map<ll, pair<pll, ll>> mp;
    mp[0] = {{0, 0}, 0};
    ll altmax = 0, ustmax = 0;
    for(int i = 1; i <= q; i++){
        ll x;
        cin>>x;
        curdel += x;
        if(curdel < altmax){
            altmax = curdel;
            mp[-altmax + ustmax] = {{-altmax, ustmax}, 0};
        }else if(curdel > ustmax){
            ustmax = curdel;
            mp[-altmax + ustmax] = {{-altmax, ustmax}, 1};
        }
    }

    for(int i = 0; i <= n; i++){
        ll delta = x[i + 1] - x[i];
        auto u = mp.lower_bound(delta);
        if(u == mp.end()){
            ans[i] += (*prev(u)).ss.ff.ss;
            ans[i + 1] += ((*prev(u)).ss.ff.ff);
        }else{
            //cout<<delta<<" "<<(*u).ff<<" "<<(*u).ss.ff.ff<<" "<<(*u).ss.ff.ss<<" "<<(*u).ss.ss<<endl;
            ans[i + 1] += (*u).ss.ff.ff;
            ans[i] += (*u).ss.ff.ss;
            ans[i + !(*u).ss.ss] -= ((*u).ff - delta);
        }
    }

    for(int i = 1; i <= n; i++)
        cout<<ans[i]<<endl;


    #ifdef Local
        cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 2 ms 620 KB Output is correct
5 Correct 2 ms 620 KB Output is correct
6 Correct 2 ms 620 KB Output is correct
7 Correct 2 ms 620 KB Output is correct
8 Correct 2 ms 620 KB Output is correct
9 Correct 2 ms 492 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 3 ms 620 KB Output is correct
16 Correct 3 ms 620 KB Output is correct
17 Correct 3 ms 620 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 2 ms 620 KB Output is correct
5 Correct 2 ms 620 KB Output is correct
6 Correct 2 ms 620 KB Output is correct
7 Correct 2 ms 620 KB Output is correct
8 Correct 2 ms 620 KB Output is correct
9 Correct 2 ms 492 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 3 ms 620 KB Output is correct
16 Correct 3 ms 620 KB Output is correct
17 Correct 3 ms 620 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 81 ms 18156 KB Output is correct
21 Correct 78 ms 18028 KB Output is correct
22 Correct 79 ms 17772 KB Output is correct
23 Correct 76 ms 17644 KB Output is correct
24 Correct 91 ms 18156 KB Output is correct
25 Correct 263 ms 24376 KB Output is correct
26 Correct 258 ms 24044 KB Output is correct
27 Correct 255 ms 22636 KB Output is correct
28 Correct 234 ms 21484 KB Output is correct
29 Correct 179 ms 14828 KB Output is correct
30 Correct 103 ms 7532 KB Output is correct
31 Correct 71 ms 6892 KB Output is correct
32 Correct 64 ms 7020 KB Output is correct
33 Correct 15 ms 2412 KB Output is correct
34 Correct 103 ms 9620 KB Output is correct
35 Correct 114 ms 10092 KB Output is correct
36 Correct 246 ms 23404 KB Output is correct
37 Correct 222 ms 19436 KB Output is correct
38 Correct 246 ms 22764 KB Output is correct
39 Correct 187 ms 22764 KB Output is correct
40 Correct 135 ms 22764 KB Output is correct
41 Correct 78 ms 18796 KB Output is correct
42 Correct 67 ms 7020 KB Output is correct
43 Correct 146 ms 25964 KB Output is correct
44 Correct 81 ms 18608 KB Output is correct
45 Correct 139 ms 22764 KB Output is correct
46 Correct 172 ms 26244 KB Output is correct
47 Correct 115 ms 16000 KB Output is correct
48 Correct 151 ms 26476 KB Output is correct