답안 #1087141

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1087141 2024-09-12T08:48:05 Z avighna Lasers (NOI19_lasers) C++17
41 / 100
200 ms 262144 KB
#include <bits/stdc++.h>

typedef long long ll;

class SegmentTree {
public:
  std::vector<ll> seg;
  ll n;

  SegmentTree(ll n) {
    this->n = n;
    seg.resize(4 * n);
  }

  ll f(ll a, ll b) { return a + b; }
  ll idt() { return 0; }

  ll query(ll v, ll tl, ll tr, ll l, ll r) {
    if (tl > tr || l > r || tr < l || r < tl) {
      return idt();
    }
    if (l <= tl && tr <= r) {
      return seg[v];
    }
    ll tm = (tl + tr) / 2;
    return f(query(2 * v, tl, tm, l, r), query(2 * v + 1, tm + 1, tr, l, r));
  }
  ll query(ll l, ll r) { return query(1, 0, n, l, r); }

  void update(ll v, ll tl, ll tr, ll idx, ll del) {
    if (tl > tr || (!(tl <= idx && idx <= tr))) {
      return;
    }
    seg[v] += del;
    if (tl != tr) {
      ll tm = (tl + tr) / 2;
      update(2 * v, tl, tm, idx, del);
      update(2 * v + 1, tm + 1, tr, idx, del);
      seg[v] = f(seg[2 * v], seg[2 * v + 1]);
    }
  }
  void update(ll idx, ll del) { update(1, 0, n, idx, del); }
};

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);
  SegmentTree tree(l + 1);
  // 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.update(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.update(f(i), -1);
      left[i] = l;
      tree.update(f(i), 1);
      if (!rows[i].empty()) {
        pq.push({left[i] + rows[i][0], i});
        rows[i].pop_front();
      }
    }
    ans += tree.query(_i + 1, l + 1) != r;
  }
  std::cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 166 ms 31068 KB Output is correct
2 Correct 109 ms 30300 KB Output is correct
3 Correct 136 ms 31336 KB Output is correct
4 Correct 175 ms 32792 KB Output is correct
5 Correct 130 ms 32856 KB Output is correct
6 Correct 195 ms 32084 KB Output is correct
7 Correct 76 ms 25944 KB Output is correct
8 Correct 200 ms 30800 KB Output is correct
9 Correct 147 ms 30812 KB Output is correct
10 Correct 194 ms 31576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 2 ms 1116 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 166 ms 31068 KB Output is correct
2 Correct 109 ms 30300 KB Output is correct
3 Correct 136 ms 31336 KB Output is correct
4 Correct 175 ms 32792 KB Output is correct
5 Correct 130 ms 32856 KB Output is correct
6 Correct 195 ms 32084 KB Output is correct
7 Correct 76 ms 25944 KB Output is correct
8 Correct 200 ms 30800 KB Output is correct
9 Correct 147 ms 30812 KB Output is correct
10 Correct 194 ms 31576 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 1116 KB Output is correct
18 Correct 1 ms 1116 KB Output is correct
19 Correct 2 ms 1116 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Runtime error 103 ms 262144 KB Execution killed with signal 9
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -