답안 #1011014

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1011014 2024-06-29T16:59:15 Z gaurezzz 식물 비교 (IOI20_plants) C++17
컴파일 오류
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 <ll> 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;
}

int main (){

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	init(4, {0,2,1,0,3,3,3});
    cout << compare_plants(0,3) << nd;
    cout << compare_plants(1,2) << nd;

    return 0;
}

Compilation message

/usr/bin/ld: /tmp/cc2HnLTx.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccRtjWNv.o:plants.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/cc2HnLTx.o: in function `main':
grader.cpp:(.text.startup+0x2f6): undefined reference to `init(int, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status