Submission #1011018

# Submission time Handle Problem Language Result Execution time Memory
1011018 2024-06-29T17:01:21 Z gaurezzz Comparing Plants (IOI20_plants) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

#define F first 
#define S second
#define ll long long
#define nd '\n'

using namespace std;

vector <ll> plants;
vector <ll> finale;
ll k;
ll n;

struct nodo {

    ll limIz, limDe;
    ll lazy;
    ll v;
    ll medio;
    ll minimo;
    ll posMinimo;
    nodo *left, *right;

    nodo(ll iz, ll de){ limIz = iz, limDe = de;}

    void build (){

        if (limIz == limDe){
            v = plants[limIz];
            minimo = v;
            posMinimo = limIz;
            return;
        }

        medio = (limDe+limIz)/2;

        left = new nodo(limIz, medio);
        right = new nodo(medio+1, limDe);

        left->build();
        right->build();

        v = left->v + right-> v;
        if (left->minimo <= right->minimo)
        minimo = left->minimo, posMinimo = left->posMinimo;
        else minimo = right->minimo, posMinimo = right->posMinimo;

        //cout << "nodo: " << limIz << " " << limDe << nd;
        //cout << "v: " << v << " minimo: " << minimo << " pos: " << posMinimo<< nd;
    }

    void updateLazy(){

        if (lazy == 0) return;

        v+=(limDe-limIz+1)*lazy;
        minimo+=lazy;

        //cout << "lazy " << lazy << " min " << minimo << nd;

        if (limIz != limDe) left->lazy+=lazy, right->lazy+=lazy;

        lazy=0;
    }

    void update (ll upL, ll upR, ll v){

        //cout << limIz << " entrandou " << limDe << nd;
        updateLazy();

        if (upL <= limIz && limDe <= upR){
            lazy+=v;
            //cout << limIz << " laziando " << limDe << nd;
            updateLazy();
            return;
        }

        if (limIz > upR || limDe < upL) return;

        left->update(upL, upR, v);
        right->update(upL, upR, v);

        v = left->v + right->v;
        if (left->minimo <= right->minimo)
        minimo = left->minimo, posMinimo = left->posMinimo;
        else minimo = right->minimo, posMinimo = right->posMinimo;

        //cout << "nodo: " << limIz << " " << limDe << nd;
        //cout << "v: " << v << " minimo: " << minimo << nd;
    }

    pair <ll,ll> query (ll qL, ll qR){

        //cout << limIz << " entrando " << limDe << nd;

        updateLazy();

        if (qL <= limIz && limDe <= qR){
            //cout << "query: " << limIz << " " << limDe << nd;
            //cout << minimo << " x " << posMinimo << nd;
            return {minimo, posMinimo};
        }

        if (limIz > qR || limDe < qL) return {INT_MAX, -1};

        pair <ll,ll> a = left->query(qL, qR);
        pair <ll,ll> b = right->query(qL, qR);

        //cout << "query: " << limIz << " " << limDe << nd;
        //cout << a.F << " " << a.S << " " << b.F << " " << b.S << nd; 

        if (a.F <= b.F) return a;
        else return b;
    }
};

pair<ll,ll> procesarConsulta(int l, int r, nodo *st){

    //cout << l << " " << r << nd;

    if (l <= r) return st->query(l, r-1);
    
    pair <ll,ll> a = st->query(l, n-1);

    if (r == 0) return a;

    pair <ll,ll> b = st->query(0, r-1);

    if (a.F <= b.F) return a;
    else return b;
}

void procesarUpdate(int l, int r, nodo *st){

    //cout << "actualizando" << l << " " << r << nd;

    if (l <= r){ st->update(l, r-1, -1); return;}
    
    st->update(l, n-1, -1);

    if (r == 0) return;

    st->update(0, r-1, -1);
}

nodo *st;

void init (int K, vector <int> r){

    plants = r;
    k=K;

    n = r.size();

    st = new nodo(0, n-1);

    st->build();

    finale.assign(n,1);
    ll orden=0;

    pair <ll,ll> cero = st->query(0, n-1);

    //cout << 1 << nd;

    auto posible = procesarConsulta((cero.S-k+1+n)%n, cero.S, st);

    //cout << "posible  " << posible.F << " " << posible.S << nd;

    if (posible.F == 0) cero = posible;

    for (ll i=0; i<n; i++){

        //cout << i << nd;

        procesarUpdate((cero.S-k+1+n)%n, cero.S, st);
        //cout << "aaa" << nd;
        st->update(cero.S, cero.S, INT_MAX);

        finale[cero.S] = orden--;

        vector <pair <ll,ll>> s;

        for (ll i=0; i<n; i++) {
            s.push_back(st->query(i,i));
        }
        //for (ll i=0; i<n; i++) {
            //cout << s[i].F << " ";
        //}
        //cout << nd;

        //for (ll i=0; i<n; i++) cout << finale[i] << " ";
    //cout << nd;

        if (i == n-1) break;
        cero = procesarConsulta((cero.S-k+1+n)%n, cero.S, st);
        if (cero.F != 0) cero = st->query(0, n-1);
        auto posible = procesarConsulta((cero.S-k+1+n)%n, cero.S, st);
        //cout << cero.S << " ceros " << posible.S << nd;
        if (posible.F == 0) cero = posible;
    }
}

int compare_plants(int x, int y){

	if (finale[x] > finale[y]) return 1;
    else return -1;
}

Compilation message

plants.cpp: In function 'void init(int, std::vector<int>)':
plants.cpp:151:14: error: no match for 'operator=' (operand types are 'std::vector<long long int>' and 'std::vector<int>')
  151 |     plants = r;
      |              ^
In file included from /usr/include/c++/10/vector:72,
                 from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from plants.cpp:1:
/usr/include/c++/10/bits/vector.tcc:198:5: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = long long int; _Alloc = std::allocator<long long int>]'
  198 |     vector<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/10/bits/vector.tcc:199:42: note:   no known conversion for argument 1 from 'std::vector<int>' to 'const std::vector<long long int>&'
  199 |     operator=(const vector<_Tp, _Alloc>& __x)
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from plants.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:709:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = long long int; _Alloc = std::allocator<long long int>]'
  709 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:709:26: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::vector<long long int>&&'
  709 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |                 ~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:730:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = long long int; _Alloc = std::allocator<long long int>]'
  730 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:730:46: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::initializer_list<long long int>'
  730 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~