Submission #601439

# Submission time Handle Problem Language Result Execution time Memory
601439 2022-07-21T22:12:41 Z Ozy Snowball (JOI21_ho_t2) C++17
100 / 100
105 ms 15368 KB
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define rep(i,a,b) for (int i = (a); i <= (b); i++)
#define repa(i,a,b) for (int i = (a); i >= (b); i--)

#define MAX 200000

lli der[MAX+2],izq[MAX+2],sum[MAX+2];
lli arr[MAX+2];
lli l,r,n,q,a,pos,dif,b;
lli res[MAX+2];

lli binaria(lli lim) {
    lli mitad,ini = 1;
    lli fin = q;
    lli ult = 0;
    while (ini <= fin) {
        mitad = (ini+fin)/2;
        if (sum[mitad] <= lim) {
            ult = mitad;
            ini = mitad+1;
        }
        else fin = mitad-1;
    }
    return ult;

}

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

    cin >> n >> q;
    rep(i,1,n) cin >> arr[i];
    l = 0;
    r = 0;
    pos = 0;
    rep(i,1,q) {
        cin >> a;
        pos += a;
        der[i] = der[i-1];
        izq[i] = izq[i-1];

        if (pos > r) {
            der[i] += pos - r;
            r = pos;
        }
        else if (pos < l) {
            izq[i] += l - pos;
            l = pos;
        }
        sum[i] = der[i] + izq[i];
    }

    res[1] -= l;
    res[n] += r;
    rep(i,2,n) {
        dif = arr[i] - arr[i-1];
        a = binaria(dif);

        res[i-1] += der[a];
        res[i] += izq[a];

        if (a == q) continue;

        dif -= sum[a];
        a++;
        if (der[a-1] != der[a]) res[i-1] += dif;
        else res[i] += dif;
    }

    rep(i,1,n) cout << res[i] << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 404 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 488 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 1 ms 464 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 0 ms 328 KB Output is correct
19 Correct 1 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 404 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 488 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 1 ms 464 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 0 ms 328 KB Output is correct
19 Correct 1 ms 464 KB Output is correct
20 Correct 26 ms 7084 KB Output is correct
21 Correct 25 ms 6888 KB Output is correct
22 Correct 25 ms 6724 KB Output is correct
23 Correct 22 ms 6604 KB Output is correct
24 Correct 29 ms 7132 KB Output is correct
25 Correct 87 ms 13388 KB Output is correct
26 Correct 90 ms 13308 KB Output is correct
27 Correct 97 ms 12964 KB Output is correct
28 Correct 87 ms 13132 KB Output is correct
29 Correct 84 ms 12708 KB Output is correct
30 Correct 82 ms 12040 KB Output is correct
31 Correct 63 ms 11468 KB Output is correct
32 Correct 52 ms 11676 KB Output is correct
33 Correct 9 ms 1692 KB Output is correct
34 Correct 89 ms 13764 KB Output is correct
35 Correct 91 ms 13144 KB Output is correct
36 Correct 86 ms 13392 KB Output is correct
37 Correct 97 ms 13172 KB Output is correct
38 Correct 105 ms 12976 KB Output is correct
39 Correct 103 ms 13204 KB Output is correct
40 Correct 65 ms 13236 KB Output is correct
41 Correct 30 ms 7724 KB Output is correct
42 Correct 51 ms 11612 KB Output is correct
43 Correct 94 ms 14900 KB Output is correct
44 Correct 29 ms 7628 KB Output is correct
45 Correct 61 ms 13200 KB Output is correct
46 Correct 73 ms 15044 KB Output is correct
47 Correct 77 ms 15296 KB Output is correct
48 Correct 73 ms 15368 KB Output is correct