#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define pii pair<ll,ll>
#define fi first
#define sec second
#define endl '\n'
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag, tree_order_statistics_node_update>
#define ordered_multiset tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update>
const ll MOD = 998244353;
const ll N = 5e5 + 5;
const ll INF = 1e18;
vector<ll>vec[N];
int32_t main(){
cin.tie(0)->sync_with_stdio(0);
int tc = 1;
// cin >> tc;
while(tc--){
ll n,q; cin >> n >> q;
for(int i=1;i<=q;i++){
ll a; cin >> a;
for(int j=1;j<=a;j++){
ll x; cin >> x;
vec[i].pb(x);
}
}
set<pii>interval;
for(int i=1;i<=q;i++){
ll l = 1;
for(auto j : vec[i]){
ll val = max(0LL, 2*j - (n-l+1));
if(val > 0) interval.insert({l-val+j, l+j-1});
l += j;
}
}
if(interval.size() == 0){
cout << 0 << endl;
continue;
}
ll last = -1, prev = -1, mx = 0, ans = 0;
for(auto i : interval){
// cout << i.fi << " " << i.sec << endl;
if(prev == -1) prev = i.fi;
if(i.fi != prev){
if(mx == 0) mx = prev-1;
ans += max(0LL, last - mx);
mx = max(mx, last);
prev = i.fi;
last = 0;
}
last = i.sec;
}
if(mx == 0) ans += max(0LL, last - prev + 1);
else ans += max(0LL, last - mx);
cout << ans << endl;
}
}
/*
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12376 KB |
Output is correct |
2 |
Correct |
2 ms |
12120 KB |
Output is correct |
3 |
Correct |
2 ms |
12124 KB |
Output is correct |
4 |
Correct |
2 ms |
12124 KB |
Output is correct |
5 |
Correct |
2 ms |
12128 KB |
Output is correct |
6 |
Correct |
2 ms |
12124 KB |
Output is correct |
7 |
Correct |
2 ms |
12124 KB |
Output is correct |
8 |
Correct |
2 ms |
12120 KB |
Output is correct |
9 |
Correct |
2 ms |
12120 KB |
Output is correct |
10 |
Correct |
2 ms |
12124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12376 KB |
Output is correct |
2 |
Correct |
2 ms |
12120 KB |
Output is correct |
3 |
Correct |
2 ms |
12124 KB |
Output is correct |
4 |
Correct |
2 ms |
12124 KB |
Output is correct |
5 |
Correct |
2 ms |
12128 KB |
Output is correct |
6 |
Correct |
2 ms |
12124 KB |
Output is correct |
7 |
Correct |
2 ms |
12124 KB |
Output is correct |
8 |
Correct |
2 ms |
12120 KB |
Output is correct |
9 |
Correct |
2 ms |
12120 KB |
Output is correct |
10 |
Correct |
2 ms |
12124 KB |
Output is correct |
11 |
Correct |
2 ms |
12124 KB |
Output is correct |
12 |
Correct |
62 ms |
27396 KB |
Output is correct |
13 |
Correct |
2 ms |
12124 KB |
Output is correct |
14 |
Correct |
2 ms |
12124 KB |
Output is correct |
15 |
Correct |
2 ms |
12124 KB |
Output is correct |
16 |
Correct |
2 ms |
12136 KB |
Output is correct |
17 |
Correct |
134 ms |
40616 KB |
Output is correct |
18 |
Correct |
2 ms |
12124 KB |
Output is correct |
19 |
Correct |
2 ms |
12124 KB |
Output is correct |
20 |
Correct |
3 ms |
12124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
16336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
12124 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
16336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12376 KB |
Output is correct |
2 |
Correct |
2 ms |
12120 KB |
Output is correct |
3 |
Correct |
2 ms |
12124 KB |
Output is correct |
4 |
Correct |
2 ms |
12124 KB |
Output is correct |
5 |
Correct |
2 ms |
12128 KB |
Output is correct |
6 |
Correct |
2 ms |
12124 KB |
Output is correct |
7 |
Correct |
2 ms |
12124 KB |
Output is correct |
8 |
Correct |
2 ms |
12120 KB |
Output is correct |
9 |
Correct |
2 ms |
12120 KB |
Output is correct |
10 |
Correct |
2 ms |
12124 KB |
Output is correct |
11 |
Correct |
2 ms |
12124 KB |
Output is correct |
12 |
Correct |
62 ms |
27396 KB |
Output is correct |
13 |
Correct |
2 ms |
12124 KB |
Output is correct |
14 |
Correct |
2 ms |
12124 KB |
Output is correct |
15 |
Correct |
2 ms |
12124 KB |
Output is correct |
16 |
Correct |
2 ms |
12136 KB |
Output is correct |
17 |
Correct |
134 ms |
40616 KB |
Output is correct |
18 |
Correct |
2 ms |
12124 KB |
Output is correct |
19 |
Correct |
2 ms |
12124 KB |
Output is correct |
20 |
Correct |
3 ms |
12124 KB |
Output is correct |
21 |
Incorrect |
13 ms |
16336 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |