Submission #1140303

#TimeUsernameProblemLanguageResultExecution timeMemory
1140303goatmar송신탑 (IOI22_towers)C++20
Compilation error
0 ms0 KiB
#include <vector> #include <algorithm> #include <iostream> #include <climits> using namespace std; vector<int> H; int N; // Segment Tree for Range Maximum Query (RMQ) class SegmentTree { private: vector<int> tree; int n; void build(int node, int start, int end) { if (start == end) { tree[node] = H[start]; } else { int mid = (start + end) / 2; build(2 * node, start, mid); build(2 * node + 1, mid + 1, end); tree[node] = max(tree[2 * node], tree[2 * node + 1]); } } int query(int node, int start, int end, int l, int r) { if (r < start || l > end) { return INT_MIN; } if (l <= start && end <= r) { return tree[node]; } int mid = (start + end) / 2; int left = query(2 * node, start, mid, l, r); int right = query(2 * node + 1, mid + 1, end, l, r); return max(left, right); } public: SegmentTree(int size) { n = size; tree.resize(4 * n); build(1, 0, n - 1); } int getMax(int l, int r) { return query(1, 0, n - 1, l, r); } }; SegmentTree* st; void init(int N, vector<int> H) { ::N = N; ::H = H; st = new SegmentTree(N); } int max_towers(int L, int R, int D) { int maxH = st->getMax(L, R); int count = 0; int last = -1; for (int i = L; i <= R; ++i) { if (H[i] <= maxH - D) { if (last == -1 || H[i] >= H[last]) { last = i; count++; } } } return count; } int main() { // Example usage init(7, {10, 20, 60, 40, 50, 30, 70}); cout << max_towers(1, 5, 10) << endl; // Output: 3 cout << max_towers(2, 2, 100) << endl; // Output: 1 cout << max_towers(0, 6, 17) << endl; // Output: 2 // Clean up delete st; return 0; }

Compilation message (stderr)

/usr/bin/ld: /tmp/ccswtGiv.o: in function `main':
stub.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccvQzRtv.o:towers.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status