Submission #1087147

# Submission time Handle Problem Language Result Execution time Memory
1087147 2024-09-12T08:49:48 Z avighna Lasers (NOI19_lasers) C++17
41 / 100
137 ms 262144 KB
#include <bits/stdc++.h>

class FenwickTree {
public:
  std::vector<int> f;
  int n;

  FenwickTree(int n) {
    this->n = n;
    f.resize(n + 1);
  }

  void add(int idx, int del) {
    for (int i = idx; i <= n; i += i & (-i)) {
      f[i] += del;
    }
  }

  int query(int idx) {
    int ans = 0;
    for (int i = idx; i >= 1; i -= i & (-i)) {
      ans += f[i];
    }
    return ans;
  }
  int query(int l, int r) {
    if (l > r) {
      return 0;
    }
    int ans = query(r);
    if (l - 1 >= 1) {
      ans -= query(l - 1);
    }
    return ans;
  }
};

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

  int l, r;
  std::cin >> l >> r;
  std::priority_queue<std::pair<int, int>, std::vector<std::pair<int, int>>,
                      std::greater<>>
      pq;
  std::vector<int> left(r), sum(r);
  std::vector<std::deque<int>> rows(r);
  FenwickTree tree(l + 1);
  // x blocks from right ==> l - x + 1 from left
  auto f = [&](int cnt) { return l - (sum[cnt] - left[cnt]) + 1; };
  for (int cnt = 0; cnt < r; ++cnt) {
    auto &v = rows[cnt];
    int len;
    std::cin >> len;
    v.resize(len);
    for (auto &i : v) {
      std::cin >> i;
    }
    sum[cnt] = std::accumulate(v.begin(), v.end(), 0);
    pq.push({left[cnt] + v[0], cnt});
    v.pop_front();
    tree.add(f(cnt), 1);
  }

  int ans = 0;
  for (int _i = 1; _i <= l; ++_i) {
    while (!pq.empty() and pq.top().first < _i) {
      auto [l, i] = pq.top();
      pq.pop();
      tree.add(f(i), -1);
      left[i] = l;
      tree.add(f(i), 1);
      if (!rows[i].empty()) {
        pq.push({left[i] + rows[i][0], i});
        rows[i].pop_front();
      }
    }
    int gs = tree.query(_i + 1, l + 1);
    // for (int j = 0; j < r; ++j) {
    //   gs += _i < l - (sum[j] - left[j]) + 1;
    // }
    ans += gs != r;
  }
  std::cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Runtime error 137 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 137 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 52 ms 5724 KB Output is correct
2 Correct 37 ms 4444 KB Output is correct
3 Correct 28 ms 4696 KB Output is correct
4 Correct 57 ms 5980 KB Output is correct
5 Correct 33 ms 5208 KB Output is correct
6 Correct 62 ms 6116 KB Output is correct
7 Correct 14 ms 3676 KB Output is correct
8 Correct 70 ms 6492 KB Output is correct
9 Correct 33 ms 4956 KB Output is correct
10 Correct 54 ms 5944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 5724 KB Output is correct
2 Correct 37 ms 4444 KB Output is correct
3 Correct 28 ms 4696 KB Output is correct
4 Correct 57 ms 5980 KB Output is correct
5 Correct 33 ms 5208 KB Output is correct
6 Correct 62 ms 6116 KB Output is correct
7 Correct 14 ms 3676 KB Output is correct
8 Correct 70 ms 6492 KB Output is correct
9 Correct 33 ms 4956 KB Output is correct
10 Correct 54 ms 5944 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 860 KB Output is correct
18 Correct 1 ms 972 KB Output is correct
19 Correct 1 ms 1116 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Runtime error 127 ms 262144 KB Execution killed with signal 9
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 137 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -