Submission #1015815

# Submission time Handle Problem Language Result Execution time Memory
1015815 2024-07-06T21:16:33 Z MilosMilutinovic Plahte (COCI17_plahte) C++14
128 / 160
302 ms 524288 KB
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(n), c(n), d(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  vector<int> x(m), y(m), k(m);
  for (int i = 0; i < m; i++) {
    cin >> x[i] >> y[i] >> k[i];
  }
  vector<int> xs;
  for (int i = 0; i < n; i++) {
    xs.push_back(b[i]);
    xs.push_back(d[i]);
  }
  for (int i = 0; i < m; i++) {
    xs.push_back(y[i]);
  }
  sort(xs.begin(), xs.end());
  xs.erase(unique(xs.begin(), xs.end()), xs.end());
  for (int i = 0; i < n; i++) {
    b[i] = (int) (lower_bound(xs.begin(), xs.end(), b[i]) - xs.begin());
    d[i] = (int) (lower_bound(xs.begin(), xs.end(), d[i]) - xs.begin());
  }
  for (int i = 0; i < m; i++) {
    y[i] = (int) (lower_bound(xs.begin(), xs.end(), y[i]) - xs.begin());
  }
  vector<array<int, 3>> ev;
  for (int i = 0; i < n; i++) {
    ev.push_back({a[i], i, 0});
    ev.push_back({c[i] + 1, ~i, 1});
  }
  for (int i = 0; i < m; i++) {
    ev.push_back({x[i], n + i, 2});
  }
  sort(ev.begin(), ev.end());
  vector<vector<int>> g(n);
  vector<set<int>> col(n);
  int lst;
  vector<vector<int>> stk(24 * n);
  function<void(int, int, int, int, int, int)> Insert = [&](int id, int l, int r, int ll, int rr, int v) {
    if (ll <= l && r <= rr) {
      stk[id].push_back(v);
      return;
    }
    int mid = (l + r) >> 1;
    if (rr <= mid) {
      Insert(id * 2, l, mid, ll, rr, v);
    } else if (ll > mid) {
      Insert(id * 2 + 1, mid + 1, r, ll, rr, v);
    } else {
      Insert(id * 2, l, mid, ll, rr, v);
      Insert(id * 2 + 1, mid + 1, r, ll, rr, v);
    }
  };
  function<void(int, int, int, int, int)> Pop = [&](int id, int l, int r, int ll, int rr) {
    if (ll <= l && r <= rr) {
      stk[id].pop_back();
      return;
    }
    int mid = (l + r) >> 1;
    if (rr <= mid) {
      Pop(id * 2, l, mid, ll, rr);
    } else if (ll > mid) {
      Pop(id * 2 + 1, mid + 1, r, ll, rr);
    } else {
      Pop(id * 2, l, mid, ll, rr);
      Pop(id * 2 + 1, mid + 1, r, ll, rr);
    }
  };
  function<void(int, int, int, int)> Query = [&](int id, int l, int r, int p) {
    if (!stk[id].empty()) {
      lst = stk[id].back();
    }
    if (l == r) {
      return;
    }
    int mid = (l + r) >> 1;
    if (p <= mid) {
      Query(id * 2, l, mid, p);
    } else {
      Query(id * 2 + 1, mid + 1, r, p);
    }
  };
  for (auto& p : ev) {
    int i = p[1];
    if (p[2] == 0) {
      lst = -1;
      Query(1, 0, 3 * n - 1, b[i]);
      Insert(1, 0, 3 * n - 1, b[i], d[i], i);
      if (lst != -1) {
        g[lst].push_back(i);
      }
    }
    if (p[2] == 1) {
      i = ~i;
      Pop(1, 0, 3 * n - 1, b[i], d[i]);
    }
    if (p[2] == 2) {
      i -= n;
      lst = -1;
      Query(1, 0, 3 * n - 1, y[i]);
      if (lst != -1) {
        col[lst].insert(k[i]);
      }
    }
  }
  vector<bool> root(n, true);
  for (int i = 0; i < n; i++) {
    for (int j : g[i]) {
      root[j] = false;
    }
  }
  vector<int> res(n);
  vector<int> where(n);
  function<void(int)> Dfs = [&](int v) {
    where[v] = v;
    for (int u : g[v]) {
      Dfs(u);
      if (col[where[v]].size() < col[where[u]].size()) {
        swap(where[v], where[u]);
      }
      for (int c : col[where[u]]) {
        col[where[v]].insert(c);
      }
      col[where[u]].clear();
    }
    res[v] = (int) col[where[v]].size();
  };
  for (int i = 0; i < n; i++) {
    if (root[i]) {
      Dfs(i);
    }
  }
  for (int i = 0; i < n; i++) {
    cout << res[i] << '\n';
  }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 258 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 88 ms 29392 KB Output is correct
2 Correct 81 ms 27968 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 163 ms 50572 KB Output is correct
2 Correct 155 ms 45828 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 251 ms 81096 KB Output is correct
2 Correct 281 ms 72860 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 302 ms 78568 KB Output is correct
2 Correct 282 ms 72388 KB Output is correct
3 Correct 0 ms 344 KB Output is correct