#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;
}
}
ll last = -1, prev = -1, mx = 0, ans = 0;
for(auto i : interval){
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 |
Incorrect |
2 ms |
12124 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 |
15 ms |
16352 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 |
15 ms |
16352 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 |
- |