Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define all(x) begin(x), end(x)
- using namespace std;
- using ll = long long;
- vector<string> Build(int v, int tl, int tr, vector<int>& a) {
- int mx = *max_element(begin(a) + tl, begin(a) + tr);
- string cur = string("[") + to_string(tl) + string(",") + to_string(tr) + string("):{") + to_string(mx) + string("}");
- if (tl + 1 < tr) {
- int tm = (tl + tr) >> 1;
- auto left = Build(v * 2 + 1, tl, tm, a);
- auto right = Build(v * 2 + 2, tm, tr, a);
- int h = max(left.size(), right.size()) + 3;
- int w = max({cur.size(), left[0].size() + 1 + right[0].size()});
- int left_from = 0;
- int right_from = left[0].size() + 1;
- vector<string> answer(h, string(w, ' '));
- for (int i = 0; i < cur.size(); i++) {
- answer[0][i] = cur[i];
- }
- answer[1][0] = '|';
- answer[2][0] = 'v';
- for (int i = 0; i < left.size(); i++) {
- for (int j = 0; j < left[0].size(); j++) {
- answer[3 + i][j] = left[i][j];
- }
- }
- answer[1][2] = '+';
- answer[1][right_from] = '+';
- for (int i = 3; i < right_from; i++) {
- answer[1][i] = '-';
- }
- answer[2][right_from] = 'v';
- for (int i = 0; i < right.size(); i++) {
- for (int j = 0; j < right[0].size(); j++) {
- answer[3 + i][j + right_from] = right[i][j];
- }
- }
- return answer;
- } else {
- return {cur};
- }
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int n;
- cin >> n;
- vector<int> a(n);
- for (int i = 0; i < n; i++) {
- cin >> a[i];
- }
- auto ans = Build(0, 0, n, a);
- for (auto& s : ans) {
- cout << s << '\n';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement