#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>
const int mxn = 1e6+10;
ll R,L;
int arr[mxn];
vector<pii> range;
vector<int> all;
void GO(){
int n;
cin>>n;
int arr[n];
int ls = 0,rs = 0;
for(auto &i:arr){
cin>>i;
rs += i;
}
vector<pll> v;
for(auto &i:arr){
v.push_back({ls+1,L-rs+1});
ls += i;
rs -= i;
}
v.push_back({ls+1,L-rs+1});
vector<pll> tmp;
for(auto &i:v){
if(tmp.empty()||tmp.back().sc<i.fs)tmp.push_back(i);
else tmp.back().sc = max(i.sc,tmp.back().sc);
}
for(auto &i:tmp)range.push_back(i);
return;
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>L>>R;
for(int i = 0;i<R;i++)GO();
for(auto &i:range){
all.push_back(i.fs);
all.push_back(i.sc);
}
sort(all.begin(),all.end());
all.resize(unique(all.begin(),all.end())-all.begin());
for(auto &i:range){
int l = lower_bound(all.begin(),all.end(),i.fs)-all.begin();
int r = lower_bound(all.begin(),all.end(),i.sc)-all.begin();
arr[l]++;
arr[r]--;
}
int ans = L;
int tsum = 0;
for(int i = 0;i<all.size();i++){
tsum += arr[i];
if(tsum == R)ans -= all[i+1]-all[i];
}
cout<<ans;
}
Compilation message
lasers.cpp: In function 'int main()':
lasers.cpp:61:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | for(int i = 0;i<all.size();i++){
| ~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
464 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 |
464 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
464 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 |
464 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 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 |
154 ms |
28200 KB |
Output is correct |
13 |
Correct |
0 ms |
348 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 |
230 ms |
26132 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
60 ms |
12784 KB |
Output is correct |
2 |
Correct |
10 ms |
4108 KB |
Output is correct |
3 |
Correct |
10 ms |
2460 KB |
Output is correct |
4 |
Correct |
69 ms |
15156 KB |
Output is correct |
5 |
Correct |
28 ms |
6932 KB |
Output is correct |
6 |
Correct |
38 ms |
11984 KB |
Output is correct |
7 |
Correct |
1 ms |
856 KB |
Output is correct |
8 |
Correct |
40 ms |
17652 KB |
Output is correct |
9 |
Correct |
37 ms |
8272 KB |
Output is correct |
10 |
Correct |
77 ms |
14408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 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 |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
60 ms |
12784 KB |
Output is correct |
2 |
Correct |
10 ms |
4108 KB |
Output is correct |
3 |
Correct |
10 ms |
2460 KB |
Output is correct |
4 |
Correct |
69 ms |
15156 KB |
Output is correct |
5 |
Correct |
28 ms |
6932 KB |
Output is correct |
6 |
Correct |
38 ms |
11984 KB |
Output is correct |
7 |
Correct |
1 ms |
856 KB |
Output is correct |
8 |
Correct |
40 ms |
17652 KB |
Output is correct |
9 |
Correct |
37 ms |
8272 KB |
Output is correct |
10 |
Correct |
77 ms |
14408 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 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 |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
256 ms |
26320 KB |
Output is correct |
22 |
Correct |
32 ms |
4424 KB |
Output is correct |
23 |
Correct |
16 ms |
4296 KB |
Output is correct |
24 |
Correct |
64 ms |
10432 KB |
Output is correct |
25 |
Correct |
256 ms |
25228 KB |
Output is correct |
26 |
Correct |
66 ms |
5976 KB |
Output is correct |
27 |
Correct |
25 ms |
4180 KB |
Output is correct |
28 |
Correct |
248 ms |
25472 KB |
Output is correct |
29 |
Correct |
244 ms |
25024 KB |
Output is correct |
30 |
Correct |
45 ms |
7592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
464 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 |
464 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 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 |
154 ms |
28200 KB |
Output is correct |
13 |
Correct |
0 ms |
348 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 |
230 ms |
26132 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
60 ms |
12784 KB |
Output is correct |
22 |
Correct |
10 ms |
4108 KB |
Output is correct |
23 |
Correct |
10 ms |
2460 KB |
Output is correct |
24 |
Correct |
69 ms |
15156 KB |
Output is correct |
25 |
Correct |
28 ms |
6932 KB |
Output is correct |
26 |
Correct |
38 ms |
11984 KB |
Output is correct |
27 |
Correct |
1 ms |
856 KB |
Output is correct |
28 |
Correct |
40 ms |
17652 KB |
Output is correct |
29 |
Correct |
37 ms |
8272 KB |
Output is correct |
30 |
Correct |
77 ms |
14408 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
1 ms |
344 KB |
Output is correct |
35 |
Correct |
0 ms |
344 KB |
Output is correct |
36 |
Correct |
0 ms |
344 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 |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
256 ms |
26320 KB |
Output is correct |
42 |
Correct |
32 ms |
4424 KB |
Output is correct |
43 |
Correct |
16 ms |
4296 KB |
Output is correct |
44 |
Correct |
64 ms |
10432 KB |
Output is correct |
45 |
Correct |
256 ms |
25228 KB |
Output is correct |
46 |
Correct |
66 ms |
5976 KB |
Output is correct |
47 |
Correct |
25 ms |
4180 KB |
Output is correct |
48 |
Correct |
248 ms |
25472 KB |
Output is correct |
49 |
Correct |
244 ms |
25024 KB |
Output is correct |
50 |
Correct |
45 ms |
7592 KB |
Output is correct |
51 |
Correct |
23 ms |
5336 KB |
Output is correct |
52 |
Correct |
247 ms |
25384 KB |
Output is correct |
53 |
Correct |
259 ms |
25264 KB |
Output is correct |
54 |
Correct |
41 ms |
5440 KB |
Output is correct |
55 |
Correct |
102 ms |
8988 KB |
Output is correct |
56 |
Correct |
69 ms |
10660 KB |
Output is correct |
57 |
Correct |
71 ms |
6924 KB |
Output is correct |
58 |
Correct |
249 ms |
26036 KB |
Output is correct |
59 |
Correct |
52 ms |
5936 KB |
Output is correct |
60 |
Correct |
73 ms |
6968 KB |
Output is correct |