제출 #1306887

#제출 시각아이디문제언어결과실행 시간메모리
1306887chrisvilchesPlahte (COCI17_plahte)C++20
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;

struct BIT {
  BIT(const int size) : n(size + 1), A(n, 0) {}

  void range_update(const int i, const int j, const int v) {
    update(i, v);
    update(j + 1, -v);
  }

  int query(int i) const {
    i++;
    int sum = 0;
    for (; i > 0; i -= i & -i) sum += A[i];
    return sum;
  }

 private:
  const int n;
  vector<int> A;
  void update(int i, const int v) {
    i++;
    for (; i < n; i += i & -i) A[i] += v;
  }
};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n, m;
  while (cin >> n >> m) {
    vector<tuple<int, int, int>> events, points, ys;
    vector<tuple<int, int, int, int>> rectangles;

    for (int i = 0; i < n; i++) {
      int x1, y1, x2, y2;
      cin >> x1 >> y1 >> x2 >> y2;
      rectangles.emplace_back(x1, y1, x2, y2);
      events.emplace_back(x1, 0, i);
      events.emplace_back(x2, 2, ~i);
      ys.emplace_back(y1, 0, ~i);
      ys.emplace_back(y2, 2, i);
    }

    for (int i = 0; i < m; i++) {
      int x, y, color;
      cin >> x >> y >> color;
      points.emplace_back(x, y, color);
      ys.emplace_back(y, 1, i);
      events.emplace_back(x, 1, i);
    }

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

    int comp_y = 0;

    for (const auto& [y, type, i] : ys) {
      if (type == 0 || type == 2) {
        if (i < 0) {
          get<1>(rectangles[~i]) = comp_y;
        } else {
          get<3>(rectangles[i]) = comp_y;
        }
      } else {
        get<1>(points[i]) = comp_y;
      }

      comp_y++;
    }

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

    const int bit_size = comp_y + 1;
    BIT bit(bit_size);

    bit.range_update(0, bit_size - 1, -1);

    vector<int> delta(n), roots;

    vector<vector<int>> graph(n);

    vector<set<int>> values(n);

    for (const auto& [x, type, i] : events) {
      if (type == 0 || type == 2) {
        const auto [_, y1, _, y2] = rectangles[i < 0 ? ~i : i];

        if (i < 0) {
          bit.range_update(y1, y2, -delta[~i]);
          continue;
        }

        const int curr_value = bit.query(y1);
        delta[i] = i - curr_value;

        bit.range_update(y1, y2, delta[i]);

        if (curr_value == -1) {
          roots.emplace_back(i);
        } else {
          graph[curr_value].emplace_back(i);
        }
      } else {
        const auto [_, y, color] = points[i];
        const int curr_value = bit.query(y);
        if (curr_value != -1) {
          values[curr_value].emplace(color);
        }
      }
    }

    vector<int> res(n);

    const function<void(int)> dfs = [&](const int u) {
      for (const int v : graph[u]) dfs(v);

      for (const int v : graph[u]) {
        if (values[u].size() < values[v].size()) {
          values[u].swap(values[v]);
        }

        for (const int c : values[v]) {
          values[u].emplace(c);
        }
      }

      res[u] = values[u].size();
    };

    for (const int r : roots) dfs(r);

    for (const auto& x : res) {
      cout << x << endl;
    }
  }
}

컴파일 시 표준 에러 (stderr) 메시지

plahte.cpp: In function 'int main()':
plahte.cpp:88:28: error: redeclaration of 'auto _'
   88 |         const auto [_, y1, _, y2] = rectangles[i < 0 ? ~i : i];
      |                            ^
plahte.cpp:88:21: note: 'auto _' previously declared here
   88 |         const auto [_, y1, _, y2] = rectangles[i < 0 ? ~i : i];
      |                     ^
plahte.cpp:91:28: error: use of 'y1' before deduction of 'auto'
   91 |           bit.range_update(y1, y2, -delta[~i]);
      |                            ^~
plahte.cpp:91:32: error: use of 'y2' before deduction of 'auto'
   91 |           bit.range_update(y1, y2, -delta[~i]);
      |                                ^~
plahte.cpp:95:42: error: use of 'y1' before deduction of 'auto'
   95 |         const int curr_value = bit.query(y1);
      |                                          ^~
plahte.cpp:98:26: error: use of 'y1' before deduction of 'auto'
   98 |         bit.range_update(y1, y2, delta[i]);
      |                          ^~
plahte.cpp:98:30: error: use of 'y2' before deduction of 'auto'
   98 |         bit.range_update(y1, y2, delta[i]);
      |                              ^~