#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <array>
using namespace std;
#ifdef LOCAL
#define eprintf(...) {fprintf(stderr, __VA_ARGS__);fflush(stderr);}
#else
#define eprintf(...) 42
#endif
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
return (ull)rng() % B;
}
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
clock_t startTime;
double getCurrentTime() {
return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}
int l, r;
vector<pii> segs;
vector<pii> mySegs;
void addSeg(int segL, int segR) {
if(segL > segR)
return;
mySegs.emplace_back(segL, segR);
}
int main()
{
startTime = clock();
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
scanf("%d%d", &l, &r);
for (int i = 0; i < r; i++) {
int x;
scanf("%d", &x);
vector<int> a(x);
for (int j = 0; j < x; j++)
scanf("%d", &a[j]);
int sL = 0;
int sR = accumulate(a.begin(), a.end(), 0);
mySegs.clear();
addSeg(1, l - sR);
for (int j = 0; j < x; j++) {
sL += a[j];
sR -= a[j];
addSeg(sL + 1, l - sR);
}
vector<pii> events;
for (int j = 0; j < mySegs.size(); j++) {
events.emplace_back(mySegs[j].first, -1);
events.emplace_back(mySegs[j].second, 1);
}
int bal = 0, stS = -1;
sort(events.begin(), events.end());
for (int j = 0; j < events.size(); j++) {
if(events[j].second == -1) {
if(bal == 0)
stS = events[j].first;
bal++;
} else {
bal--;
if(bal == 0) {
segs.emplace_back(stS, events[j].first);
}
}
}
}
vector<pii> events;
for (int i = 0; i < segs.size(); i++) {
events.emplace_back(segs[i].first, -1);
events.emplace_back(segs[i].second, 1);
}
sort(events.begin(), events.end());
int bal = 0, ans = 0, stS = 0;
for (int i = 0; i < events.size(); i++) {
if(events[i].second == -1) {
bal++;
if(bal == r)
stS = events[i].first;
} else {
if(bal == r)
ans += events[i].first - stS + 1;
bal--;
}
}
printf("%d\n", l - ans);
}
Compilation message
lasers.cpp: In function 'int main()':
lasers.cpp:86:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
86 | for (int j = 0; j < mySegs.size(); j++) {
| ~~^~~~~~~~~~~~~~~
lasers.cpp:92:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
92 | for (int j = 0; j < events.size(); j++) {
| ~~^~~~~~~~~~~~~~~
lasers.cpp:106:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
106 | for (int i = 0; i < segs.size(); i++) {
| ~~^~~~~~~~~~~~~
lasers.cpp:112:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
112 | for (int i = 0; i < events.size(); i++) {
| ~~^~~~~~~~~~~~~~~
lasers.cpp:69:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
69 | scanf("%d%d", &l, &r);
| ~~~~~^~~~~~~~~~~~~~~~
lasers.cpp:72:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
72 | scanf("%d", &x);
| ~~~~~^~~~~~~~~~
lasers.cpp:75:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
75 | scanf("%d", &a[j]);
| ~~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
1 ms |
344 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 |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
1 ms |
344 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 |
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 |
83 ms |
6044 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 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 |
196 ms |
28208 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
11536 KB |
Output is correct |
2 |
Correct |
9 ms |
2644 KB |
Output is correct |
3 |
Correct |
14 ms |
2696 KB |
Output is correct |
4 |
Correct |
67 ms |
12836 KB |
Output is correct |
5 |
Correct |
26 ms |
8604 KB |
Output is correct |
6 |
Correct |
54 ms |
13372 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
58 ms |
17156 KB |
Output is correct |
9 |
Correct |
30 ms |
10680 KB |
Output is correct |
10 |
Correct |
61 ms |
17924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
11536 KB |
Output is correct |
2 |
Correct |
9 ms |
2644 KB |
Output is correct |
3 |
Correct |
14 ms |
2696 KB |
Output is correct |
4 |
Correct |
67 ms |
12836 KB |
Output is correct |
5 |
Correct |
26 ms |
8604 KB |
Output is correct |
6 |
Correct |
54 ms |
13372 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
58 ms |
17156 KB |
Output is correct |
9 |
Correct |
30 ms |
10680 KB |
Output is correct |
10 |
Correct |
61 ms |
17924 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 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 |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
201 ms |
26944 KB |
Output is correct |
22 |
Correct |
23 ms |
2640 KB |
Output is correct |
23 |
Correct |
14 ms |
3532 KB |
Output is correct |
24 |
Correct |
64 ms |
11376 KB |
Output is correct |
25 |
Correct |
188 ms |
26944 KB |
Output is correct |
26 |
Correct |
51 ms |
6856 KB |
Output is correct |
27 |
Correct |
18 ms |
2384 KB |
Output is correct |
28 |
Correct |
189 ms |
27032 KB |
Output is correct |
29 |
Correct |
204 ms |
27064 KB |
Output is correct |
30 |
Correct |
46 ms |
7064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
1 ms |
344 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 |
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 |
83 ms |
6044 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 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 |
196 ms |
28208 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
60 ms |
11536 KB |
Output is correct |
22 |
Correct |
9 ms |
2644 KB |
Output is correct |
23 |
Correct |
14 ms |
2696 KB |
Output is correct |
24 |
Correct |
67 ms |
12836 KB |
Output is correct |
25 |
Correct |
26 ms |
8604 KB |
Output is correct |
26 |
Correct |
54 ms |
13372 KB |
Output is correct |
27 |
Correct |
2 ms |
604 KB |
Output is correct |
28 |
Correct |
58 ms |
17156 KB |
Output is correct |
29 |
Correct |
30 ms |
10680 KB |
Output is correct |
30 |
Correct |
61 ms |
17924 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
201 ms |
26944 KB |
Output is correct |
42 |
Correct |
23 ms |
2640 KB |
Output is correct |
43 |
Correct |
14 ms |
3532 KB |
Output is correct |
44 |
Correct |
64 ms |
11376 KB |
Output is correct |
45 |
Correct |
188 ms |
26944 KB |
Output is correct |
46 |
Correct |
51 ms |
6856 KB |
Output is correct |
47 |
Correct |
18 ms |
2384 KB |
Output is correct |
48 |
Correct |
189 ms |
27032 KB |
Output is correct |
49 |
Correct |
204 ms |
27064 KB |
Output is correct |
50 |
Correct |
46 ms |
7064 KB |
Output is correct |
51 |
Correct |
18 ms |
3928 KB |
Output is correct |
52 |
Correct |
189 ms |
28400 KB |
Output is correct |
53 |
Correct |
195 ms |
28096 KB |
Output is correct |
54 |
Correct |
32 ms |
4696 KB |
Output is correct |
55 |
Correct |
85 ms |
9292 KB |
Output is correct |
56 |
Correct |
49 ms |
11228 KB |
Output is correct |
57 |
Correct |
52 ms |
7752 KB |
Output is correct |
58 |
Correct |
198 ms |
28464 KB |
Output is correct |
59 |
Correct |
40 ms |
4724 KB |
Output is correct |
60 |
Correct |
61 ms |
5720 KB |
Output is correct |