답안 #919887

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
919887 2024-02-01T19:23:33 Z vjudge1 원숭이와 사과 나무 (IZhO12_apple) C++14
컴파일 오류
0 ms 0 KB
#include <iostream>
#include <vector>

using namespace std;

// Segment tree node
struct Node {
    int left, right; // interval [left, right]
    int redApples; // number of red-ripen apple-trees in the interval
};

// Function to build the segment tree
void buildSegmentTree(vector<Node>& tree, int node, int left, int right) {
    tree[node].left = left;
    tree[node].right = right;
    tree[node].redApples = 0;

    if (left != right) {
        int mid = (left + right) / 2;
        buildSegmentTree(tree, 2 * node, left, mid);
        buildSegmentTree(tree, 2 * node + 1, mid + 1, right);
    }
}

// Function to update the segment tree with red-ripening of apples
void updateSegmentTree(vector<Node>& tree, int node, int left, int right) {
    if (tree[node].left == left && tree[node].right == right) {
        tree[node].redApples = right - left + 1;
    } else {
        int mid = (tree[node].left + tree[node].right) / 2;
        if (right <= mid) {
            updateSegmentTree(tree, 2 * node, left, right);
        } else if (left > mid) {
            updateSegmentTree(tree, 2 * node + 1, left, right);
        } else {
            updateSegmentTree(tree, 2 * node, left, mid);
            updateSegmentTree(tree, 2 * node + 1, mid + 1, right);
        }
        tree[node].redApples = tree[2 * node].redApples + tree[2 * node + 1].redApples;
    }
}

// Function to query the segment tree for the number of red-ripen apple-trees
int querySegmentTree(vector<Node>& tree, int node, int left, int right) {
    if (tree[node].left == left && tree[node].right == right) {
        return tree[node].redApples;
    } else {
        int mid = (tree[node].left + tree[node].right) / 2;
        if (right <= mid) {
            return querySegmentTree(tree, 2 * node, left, right);
        } else if (left > mid) {
            return querySegmentTree(tree, 2 * node + 1, left, right);
        } else {
            return querySegmentTree(tree, 2 * node, left, mid) + querySegmentTree(tree, 

Compilation message

apple.cpp: In function 'int querySegmentTree(std::vector<Node>&, int, int, int)':
apple.cpp:54:87: error: expected primary-expression at end of input
   54 |             return querySegmentTree(tree, 2 * node, left, mid) + querySegmentTree(tree,
      |                                                                                       ^
apple.cpp:54:88: error: expected ';' at end of input
   54 |             return querySegmentTree(tree, 2 * node, left, mid) + querySegmentTree(tree,
      |                                                                                       ~^
      |                                                                                        ;
apple.cpp:54:87: error: expected '}' at end of input
   54 |             return querySegmentTree(tree, 2 * node, left, mid) + querySegmentTree(tree,
      |                                                                                       ^
apple.cpp:53:16: note: to match this '{'
   53 |         } else {
      |                ^
apple.cpp:54: note: '-Wmisleading-indentation' is disabled from this point onwards, since column-tracking was disabled due to the size of the code/headers
   54 |             return querySegmentTree(tree, 2 * node, left, mid) + querySegmentTree(tree,
      | 
apple.cpp:54:87: error: expected '}' at end of input
   54 |             return querySegmentTree(tree, 2 * node, left, mid) + querySegmentTree(tree,
      |                                                                                       ^
apple.cpp:47:12: note: to match this '{'
   47 |     } else {
      |            ^
apple.cpp:54:87: error: expected '}' at end of input
   54 |             return querySegmentTree(tree, 2 * node, left, mid) + querySegmentTree(tree,
      |                                                                                       ^
apple.cpp:44:73: note: to match this '{'
   44 | int querySegmentTree(vector<Node>& tree, int node, int left, int right) {
      |                                                                         ^