Submission #1140291

#TimeUsernameProblemLanguageResultExecution timeMemory
1140291goatmarRadio Towers (IOI22_towers)C++20
Compilation error
0 ms0 KiB
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

vector<int> tower_heights;
int num_towers;

void init(int N, const vector<int>& H) {
    num_towers = N;
    tower_heights = H;
}

int max_towers(int L, int R, int D) {
    vector<int> left_max(num_towers), right_max(num_towers);

    left_max[L] = tower_heights[L];
    for (int i = L + 1; i <= R; ++i) {
        left_max[i] = max(left_max[i - 1], tower_heights[i]);
    }

    right_max[R] = tower_heights[R];
    for (int i = R - 1; i >= L; --i) {
        right_max[i] = max(right_max[i + 1], tower_heights[i]);
    }

    vector<int> valid_towers;
    for (int i = L; i <= R; ++i) {
        if (tower_heights[i] <= left_max[i] - D && tower_heights[i] <= right_max[i] - D) {
            valid_towers.push_back(tower_heights[i]);
        }
    }

    sort(valid_towers.begin(), valid_towers.end());

    return valid_towers.size();
}

int main() {
    int N, Q;
    cin >> N >> Q;
    vector<int> H(N);
    for (int i = 0; i < N; ++i) {
        cin >> H[i];
    }

    init(N, H);

    while (Q--) {
        int L, R, D;
        cin >> L >> R >> D;
        cout << max_towers(L, R, D) << endl;
    }

    return 0;
}

Compilation message (stderr)

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