Submission #413356

# Submission time Handle Problem Language Result Execution time Memory
413356 2021-05-28T14:40:07 Z ocarima Snowball (JOI21_ho_t2) C++14
0 / 100
1 ms 332 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 (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;
            if (ind == rangos.size()) break;
        }

        if (ind == rangos.size()) break;
    }

    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:59:21: 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 (ind == rangos.size()) break;
      |                 ~~~~^~~~~~~~~~~~~~~~
Main.cpp:62:17: 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]
   62 |         if (ind == rangos.size()) break;
      |             ~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -