#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lld double
#define int ll
#define usaco(fname) freopen(#fname ".in","r",stdin);freopen(#fname ".out","w",stdout);
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
// const ll INF = 1e18;
const int INF = 1e9;
const int mod = 1e9+7;
const lld PI = acos(-1.0);
int di[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dj[] = {0, 0, 1, -1, 1, -1, 1, -1};
#define debug(x) cout << #x << ": " << x << endl;
#define add(a, b) a += b, a %= mod
#define mul(a, b) ((a % mod) * (b % mod)) % mod
#define all(x) x.begin(),x.end()
void solve() {
int n,q;cin>>n>>q;
vector<pair<int, int>> intervals;
while (q--) {
int k;cin>>k;
vector<int> a(k);
for (int i = 0; i < k; i++) cin >> a[i];
int sum = accumulate(all(a),0);
int left = n-sum;
int now = 0;
for (int i = 0; i < k; i++) {
now += a[i];
intervals.push_back({now-a[i]+left+1, now});
}
}
sort(all(intervals));
int nowl = -1, nowr = -1;
int ans = 0;
// cout << intervals << endl;
for (int i = 0; i < intervals.size(); i++) {
auto [l, r] = intervals[i];
if (l > r) continue;
if (nowl == -1 && nowr == -1) {
nowl = l;
nowr = r;
continue;
}
if (l > nowr) {
ans += nowr-nowl+1;
nowl = l;
nowr = r;
}
nowr = max(nowr, r);
}
if (nowl != -1) ans += nowr-nowl+1;
cout << ans << endl;
}
int32_t main() {
ios_base::sync_with_stdio(0);cin.tie(0);
int t=1;
while(t--) solve();
return 0;
}
Compilation message
lasers.cpp: In function 'void solve()':
lasers.cpp:44:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for (int i = 0; i < intervals.size(); i++) {
| ~~^~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
63 ms |
9176 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
95 ms |
8644 KB |
Output is correct |
18 |
Correct |
1 ms |
600 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
10988 KB |
Output is correct |
2 |
Correct |
7 ms |
2540 KB |
Output is correct |
3 |
Correct |
8 ms |
2624 KB |
Output is correct |
4 |
Correct |
27 ms |
10976 KB |
Output is correct |
5 |
Correct |
17 ms |
6484 KB |
Output is correct |
6 |
Correct |
35 ms |
11676 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
47 ms |
11648 KB |
Output is correct |
9 |
Correct |
14 ms |
5836 KB |
Output is correct |
10 |
Correct |
34 ms |
11852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
408 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
10988 KB |
Output is correct |
2 |
Correct |
7 ms |
2540 KB |
Output is correct |
3 |
Correct |
8 ms |
2624 KB |
Output is correct |
4 |
Correct |
27 ms |
10976 KB |
Output is correct |
5 |
Correct |
17 ms |
6484 KB |
Output is correct |
6 |
Correct |
35 ms |
11676 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
47 ms |
11648 KB |
Output is correct |
9 |
Correct |
14 ms |
5836 KB |
Output is correct |
10 |
Correct |
34 ms |
11852 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 |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
408 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
88 ms |
9936 KB |
Output is correct |
22 |
Correct |
16 ms |
2524 KB |
Output is correct |
23 |
Correct |
9 ms |
2768 KB |
Output is correct |
24 |
Correct |
43 ms |
10028 KB |
Output is correct |
25 |
Correct |
86 ms |
9680 KB |
Output is correct |
26 |
Correct |
33 ms |
8904 KB |
Output is correct |
27 |
Correct |
13 ms |
2532 KB |
Output is correct |
28 |
Correct |
93 ms |
8656 KB |
Output is correct |
29 |
Correct |
87 ms |
10428 KB |
Output is correct |
30 |
Correct |
32 ms |
10156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
63 ms |
9176 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
95 ms |
8644 KB |
Output is correct |
18 |
Correct |
1 ms |
600 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
30 ms |
10988 KB |
Output is correct |
22 |
Correct |
7 ms |
2540 KB |
Output is correct |
23 |
Correct |
8 ms |
2624 KB |
Output is correct |
24 |
Correct |
27 ms |
10976 KB |
Output is correct |
25 |
Correct |
17 ms |
6484 KB |
Output is correct |
26 |
Correct |
35 ms |
11676 KB |
Output is correct |
27 |
Correct |
1 ms |
604 KB |
Output is correct |
28 |
Correct |
47 ms |
11648 KB |
Output is correct |
29 |
Correct |
14 ms |
5836 KB |
Output is correct |
30 |
Correct |
34 ms |
11852 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
344 KB |
Output is correct |
35 |
Correct |
0 ms |
408 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
344 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
88 ms |
9936 KB |
Output is correct |
42 |
Correct |
16 ms |
2524 KB |
Output is correct |
43 |
Correct |
9 ms |
2768 KB |
Output is correct |
44 |
Correct |
43 ms |
10028 KB |
Output is correct |
45 |
Correct |
86 ms |
9680 KB |
Output is correct |
46 |
Correct |
33 ms |
8904 KB |
Output is correct |
47 |
Correct |
13 ms |
2532 KB |
Output is correct |
48 |
Correct |
93 ms |
8656 KB |
Output is correct |
49 |
Correct |
87 ms |
10428 KB |
Output is correct |
50 |
Correct |
32 ms |
10156 KB |
Output is correct |
51 |
Correct |
11 ms |
2640 KB |
Output is correct |
52 |
Correct |
78 ms |
10572 KB |
Output is correct |
53 |
Correct |
77 ms |
10432 KB |
Output is correct |
54 |
Correct |
21 ms |
6356 KB |
Output is correct |
55 |
Correct |
49 ms |
9676 KB |
Output is correct |
56 |
Correct |
30 ms |
9028 KB |
Output is correct |
57 |
Correct |
39 ms |
9928 KB |
Output is correct |
58 |
Correct |
86 ms |
8900 KB |
Output is correct |
59 |
Correct |
28 ms |
5332 KB |
Output is correct |
60 |
Correct |
43 ms |
10184 KB |
Output is correct |