Submission #413362

# Submission time Handle Problem Language Result Execution time Memory
413362 2021-05-28T14:43:44 Z ocarima Snowball (JOI21_ho_t2) C++14
100 / 100
112 ms 17060 KB
#include<bits/stdc++.h>

using namespace std;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define lli long long int
#define vi vector<int>
#define vlli vector<long long int>
#define pii pair<int, int>
#define plli pair<lli, lli>
#define rep(i, a, b) for(lli i = (a); i <= (b); i++)
#define repa(i, a, b) for(lli i = (a); i >= (b); i--)
#define repv(x, v) for(auto x : v)
#define debug(x) cout << #x << " = " << x << endl
#define debugsl(x) cout << #x << " = " << x << ", "
#define debugarr(x, a, b) cout << #x << " = ["; rep(ii, a, b) cout << x[ii] << ", "; cout << "]\n"
#define pb push_back
#define nl "\n"

#define MAX_N 200003
#define MAX_T 25001
#define INF (1ll << 62)

#define tam first
#define nodoizq second

lli n, q, x[MAX_N], lgen, rgen, pgen, w[MAX_N], taml[MAX_N], tamr[MAX_N], ind;
vector<plli> rangos;

int main()
{
    fastio;

    cin >> n >> q;
    rep(i, 1, n) cin >> x[i];
    rep(i, 1, q) cin >> w[i];

    rep(i, 1, n) taml[i] = tamr[i] = INF;
    rep(i, 1, n - 1) rangos.emplace_back(x[i + 1] - x[i], i);
    sort(rangos.begin(), rangos.end());

    ind = pgen = 0;
    rep(i, 1, q){
        pgen += w[i]; // mueve la posicion
        lgen = min(lgen, pgen);
        rgen = max(rgen, pgen); // actualiza los limites


        while (ind < rangos.size() && rgen - lgen >= rangos[ind].tam){
            // un rango ya se termino completo
            if (w[i] < 0){ // si era moviendose a la izquierda
                tamr[rangos[ind].nodoizq] = rgen; // el nodo de la izquierda no puede consumir a la derecha mas de lo que se movio
                taml[rangos[ind].nodoizq + 1] = -(rangos[ind].tam - rgen); // el nodo de la derecha consume hacia la izquierda lo que haya sobrado
            }
            else{ // esta moviendose a la derecha
                taml[rangos[ind].nodoizq + 1] = lgen;
                tamr[rangos[ind].nodoizq] = rangos[ind].tam + lgen;
            }
            ++ind;
        }
    }

    rep(i, 1, n){
        if (taml[i] == INF) taml[i] = lgen;
        if (tamr[i] == INF) tamr[i] = rgen;
        cout << tamr[i] - taml[i] << nl;
    }

    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:49:20: 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]
   49 |         while (ind < rangos.size() && rgen - lgen >= rangos[ind].tam){
      |                ~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 2 ms 496 KB Output is correct
7 Correct 2 ms 460 KB Output is correct
8 Correct 2 ms 460 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 2 ms 456 KB Output is correct
11 Correct 2 ms 460 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 3 ms 460 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 2 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 2 ms 496 KB Output is correct
7 Correct 2 ms 460 KB Output is correct
8 Correct 2 ms 460 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 2 ms 456 KB Output is correct
11 Correct 2 ms 460 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 3 ms 460 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 2 ms 460 KB Output is correct
20 Correct 38 ms 3916 KB Output is correct
21 Correct 32 ms 3700 KB Output is correct
22 Correct 31 ms 3608 KB Output is correct
23 Correct 31 ms 3504 KB Output is correct
24 Correct 34 ms 4564 KB Output is correct
25 Correct 104 ms 15180 KB Output is correct
26 Correct 103 ms 14992 KB Output is correct
27 Correct 108 ms 14756 KB Output is correct
28 Correct 107 ms 14852 KB Output is correct
29 Correct 99 ms 14384 KB Output is correct
30 Correct 107 ms 14012 KB Output is correct
31 Correct 107 ms 13796 KB Output is correct
32 Correct 83 ms 13884 KB Output is correct
33 Correct 11 ms 2000 KB Output is correct
34 Correct 107 ms 15448 KB Output is correct
35 Correct 100 ms 14872 KB Output is correct
36 Correct 112 ms 15132 KB Output is correct
37 Correct 104 ms 14792 KB Output is correct
38 Correct 105 ms 14636 KB Output is correct
39 Correct 102 ms 14848 KB Output is correct
40 Correct 110 ms 14864 KB Output is correct
41 Correct 36 ms 4624 KB Output is correct
42 Correct 96 ms 13832 KB Output is correct
43 Correct 96 ms 16684 KB Output is correct
44 Correct 35 ms 4468 KB Output is correct
45 Correct 111 ms 14772 KB Output is correct
46 Correct 108 ms 16708 KB Output is correct
47 Correct 105 ms 16944 KB Output is correct
48 Correct 105 ms 17060 KB Output is correct