#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
const ll INF = 1e9;
const ll MOD = 998244353;
const ll MAXN = 5e5 + 5;
const ll LOG = 31;
#define vll vector <ll>
#define pll pair <ll, ll>
#define fi first
#define se second
#define endl '\n'
ll n, m;
ll b [MAXN], pf [MAXN], sf [MAXN];
vector <pll> kos, u, v;
vll ans;
void solve(){
cin >> n >> m;
for(ll i = 1; i <= m; i++){
ll z; cin >> z;
for(ll j = 1; j <= z; j++) cin >> b[j];
pf[0] = 0, sf[z+1] = 0;
for(ll j = 1; j <= z; j++) pf[j] = pf[j-1] + b[j];
for(ll j = z; j >= 1; j--) sf[j] = sf[j+1] + b[j];
kos.clear();
for(ll j = 1; j <= z; j++){
ll l = pf[j-1]+1, r = n - sf[j+1];
if(l+b[j]-1 >= r-b[j]+1){
kos.push_back({r-b[j], l});
kos.push_back({r, l+b[j]});
}
else kos.push_back({r, l});
}
sort(kos.begin(), kos.end());
u.clear();
ll ans = 0;
u.push_back({0, 0});
for(auto x : kos){
// cout << x.se << " << " << x.fi << endl;
ll l = x.se, r = x.fi;
while(!u.empty()){
if(u.back().se < l) break;
l = min(l, u.back().fi);
u.pop_back();
}
u.push_back({l, r});
}
u.push_back({n+1, n+1});
for(ll j = 1; j < u.size(); j++){
ll l = u[j-1].se+1, r = u[j].fi-1;
if(l <= r) v.push_back({r, l});
}
}
sort(v.begin(), v.end());
// for(auto x : v){
// cout << x.se << " << " << x.fi << endl;
// }
u.clear();
for(auto x : v){
ll l = x.se, r = x.fi;
while(!u.empty()){
if(u.back().se < l) break;
l = min(l, u.back().fi);
u.pop_back();
}
u.push_back({l, r});
}
ll ans = 0;
for(auto x : u){
ans += x.se - x.fi + 1;
}
cout << ans << endl;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// ll t; cin >> t;
// while(t--){
solve();
// }
}
Compilation message
lasers.cpp: In function 'void solve()':
lasers.cpp:55:25: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for(ll j = 1; j < u.size(); j++){
| ~~^~~~~~~~~~
lasers.cpp:42:12: warning: unused variable 'ans' [-Wunused-variable]
42 | ll ans = 0;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4440 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4440 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4440 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
78 ms |
17944 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
80 ms |
13968 KB |
Output is correct |
18 |
Correct |
1 ms |
4440 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
23532 KB |
Output is correct |
2 |
Correct |
10 ms |
11476 KB |
Output is correct |
3 |
Correct |
9 ms |
10712 KB |
Output is correct |
4 |
Correct |
52 ms |
30748 KB |
Output is correct |
5 |
Correct |
21 ms |
18264 KB |
Output is correct |
6 |
Correct |
32 ms |
21576 KB |
Output is correct |
7 |
Correct |
2 ms |
4696 KB |
Output is correct |
8 |
Correct |
37 ms |
23236 KB |
Output is correct |
9 |
Correct |
23 ms |
22468 KB |
Output is correct |
10 |
Correct |
47 ms |
26056 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
23532 KB |
Output is correct |
2 |
Correct |
10 ms |
11476 KB |
Output is correct |
3 |
Correct |
9 ms |
10712 KB |
Output is correct |
4 |
Correct |
52 ms |
30748 KB |
Output is correct |
5 |
Correct |
21 ms |
18264 KB |
Output is correct |
6 |
Correct |
32 ms |
21576 KB |
Output is correct |
7 |
Correct |
2 ms |
4696 KB |
Output is correct |
8 |
Correct |
37 ms |
23236 KB |
Output is correct |
9 |
Correct |
23 ms |
22468 KB |
Output is correct |
10 |
Correct |
47 ms |
26056 KB |
Output is correct |
11 |
Correct |
1 ms |
4440 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
78 ms |
12752 KB |
Output is correct |
22 |
Correct |
16 ms |
6120 KB |
Output is correct |
23 |
Correct |
12 ms |
9584 KB |
Output is correct |
24 |
Correct |
49 ms |
24916 KB |
Output is correct |
25 |
Correct |
76 ms |
12736 KB |
Output is correct |
26 |
Correct |
33 ms |
10956 KB |
Output is correct |
27 |
Correct |
13 ms |
6124 KB |
Output is correct |
28 |
Correct |
76 ms |
12828 KB |
Output is correct |
29 |
Correct |
81 ms |
13260 KB |
Output is correct |
30 |
Correct |
35 ms |
14784 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4440 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4440 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
78 ms |
17944 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
80 ms |
13968 KB |
Output is correct |
18 |
Correct |
1 ms |
4440 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
42 ms |
23532 KB |
Output is correct |
22 |
Correct |
10 ms |
11476 KB |
Output is correct |
23 |
Correct |
9 ms |
10712 KB |
Output is correct |
24 |
Correct |
52 ms |
30748 KB |
Output is correct |
25 |
Correct |
21 ms |
18264 KB |
Output is correct |
26 |
Correct |
32 ms |
21576 KB |
Output is correct |
27 |
Correct |
2 ms |
4696 KB |
Output is correct |
28 |
Correct |
37 ms |
23236 KB |
Output is correct |
29 |
Correct |
23 ms |
22468 KB |
Output is correct |
30 |
Correct |
47 ms |
26056 KB |
Output is correct |
31 |
Correct |
1 ms |
4440 KB |
Output is correct |
32 |
Correct |
1 ms |
4444 KB |
Output is correct |
33 |
Correct |
1 ms |
4444 KB |
Output is correct |
34 |
Correct |
1 ms |
4444 KB |
Output is correct |
35 |
Correct |
1 ms |
4444 KB |
Output is correct |
36 |
Correct |
1 ms |
4444 KB |
Output is correct |
37 |
Correct |
1 ms |
4444 KB |
Output is correct |
38 |
Correct |
1 ms |
4444 KB |
Output is correct |
39 |
Correct |
1 ms |
4444 KB |
Output is correct |
40 |
Correct |
1 ms |
4444 KB |
Output is correct |
41 |
Correct |
78 ms |
12752 KB |
Output is correct |
42 |
Correct |
16 ms |
6120 KB |
Output is correct |
43 |
Correct |
12 ms |
9584 KB |
Output is correct |
44 |
Correct |
49 ms |
24916 KB |
Output is correct |
45 |
Correct |
76 ms |
12736 KB |
Output is correct |
46 |
Correct |
33 ms |
10956 KB |
Output is correct |
47 |
Correct |
13 ms |
6124 KB |
Output is correct |
48 |
Correct |
76 ms |
12828 KB |
Output is correct |
49 |
Correct |
81 ms |
13260 KB |
Output is correct |
50 |
Correct |
35 ms |
14784 KB |
Output is correct |
51 |
Correct |
17 ms |
10180 KB |
Output is correct |
52 |
Correct |
83 ms |
14016 KB |
Output is correct |
53 |
Correct |
80 ms |
13748 KB |
Output is correct |
54 |
Correct |
26 ms |
8140 KB |
Output is correct |
55 |
Correct |
56 ms |
13208 KB |
Output is correct |
56 |
Correct |
40 ms |
22240 KB |
Output is correct |
57 |
Correct |
39 ms |
12532 KB |
Output is correct |
58 |
Correct |
83 ms |
14276 KB |
Output is correct |
59 |
Correct |
28 ms |
7628 KB |
Output is correct |
60 |
Correct |
38 ms |
8896 KB |
Output is correct |