#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(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.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';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
127 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
127 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
48 ms |
10328 KB |
Output is correct |
2 |
Correct |
25 ms |
8284 KB |
Output is correct |
3 |
Correct |
28 ms |
8872 KB |
Output is correct |
4 |
Correct |
46 ms |
10768 KB |
Output is correct |
5 |
Correct |
36 ms |
9564 KB |
Output is correct |
6 |
Correct |
65 ms |
11356 KB |
Output is correct |
7 |
Correct |
17 ms |
6744 KB |
Output is correct |
8 |
Correct |
64 ms |
11612 KB |
Output is correct |
9 |
Correct |
31 ms |
9304 KB |
Output is correct |
10 |
Correct |
53 ms |
10840 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 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 |
344 KB |
Output is correct |
5 |
Correct |
0 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 |
1 ms |
1112 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
48 ms |
10328 KB |
Output is correct |
2 |
Correct |
25 ms |
8284 KB |
Output is correct |
3 |
Correct |
28 ms |
8872 KB |
Output is correct |
4 |
Correct |
46 ms |
10768 KB |
Output is correct |
5 |
Correct |
36 ms |
9564 KB |
Output is correct |
6 |
Correct |
65 ms |
11356 KB |
Output is correct |
7 |
Correct |
17 ms |
6744 KB |
Output is correct |
8 |
Correct |
64 ms |
11612 KB |
Output is correct |
9 |
Correct |
31 ms |
9304 KB |
Output is correct |
10 |
Correct |
53 ms |
10840 KB |
Output is correct |
11 |
Correct |
1 ms |
344 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 |
344 KB |
Output is correct |
15 |
Correct |
0 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 |
1 ms |
1112 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Runtime error |
101 ms |
262144 KB |
Execution killed with signal 9 |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
127 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |