Submission #1087137

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

typedef long long ll;

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

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

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

  ll query(ll idx) {
    ll ans = 0;
    for (ll i = idx; i >= 1; i -= i & (-i)) {
      ans += f[i];
    }
    return ans;
  }
  ll query(ll l, ll r) {
    if (l > r) {
      return 0;
    }
    ll 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);

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

  ll ans = 0;
  for (ll _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();
      }
    }
    ll gs = tree.query(_i + 1, l + 1);
    // for (ll 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 12 ms 16368 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 12 ms 16368 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 60 ms 11372 KB Output is correct
2 Correct 30 ms 8796 KB Output is correct
3 Correct 33 ms 9152 KB Output is correct
4 Correct 56 ms 11252 KB Output is correct
5 Correct 37 ms 9780 KB Output is correct
6 Correct 70 ms 12376 KB Output is correct
7 Correct 19 ms 8280 KB Output is correct
8 Correct 79 ms 13036 KB Output is correct
9 Correct 44 ms 9820 KB Output is correct
10 Correct 54 ms 11668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8284 KB Output is correct
2 Correct 3 ms 8280 KB Output is correct
3 Correct 4 ms 8284 KB Output is correct
4 Correct 3 ms 8132 KB Output is correct
5 Correct 4 ms 8284 KB Output is correct
6 Correct 4 ms 8284 KB Output is correct
7 Correct 4 ms 8796 KB Output is correct
8 Correct 5 ms 8796 KB Output is correct
9 Correct 4 ms 8932 KB Output is correct
10 Correct 5 ms 8104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 11372 KB Output is correct
2 Correct 30 ms 8796 KB Output is correct
3 Correct 33 ms 9152 KB Output is correct
4 Correct 56 ms 11252 KB Output is correct
5 Correct 37 ms 9780 KB Output is correct
6 Correct 70 ms 12376 KB Output is correct
7 Correct 19 ms 8280 KB Output is correct
8 Correct 79 ms 13036 KB Output is correct
9 Correct 44 ms 9820 KB Output is correct
10 Correct 54 ms 11668 KB Output is correct
11 Correct 3 ms 8284 KB Output is correct
12 Correct 3 ms 8280 KB Output is correct
13 Correct 4 ms 8284 KB Output is correct
14 Correct 3 ms 8132 KB Output is correct
15 Correct 4 ms 8284 KB Output is correct
16 Correct 4 ms 8284 KB Output is correct
17 Correct 4 ms 8796 KB Output is correct
18 Correct 5 ms 8796 KB Output is correct
19 Correct 4 ms 8932 KB Output is correct
20 Correct 5 ms 8104 KB Output is correct
21 Runtime error 108 ms 262144 KB Execution killed with signal 9
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 12 ms 16368 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -