#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) ans += max(0LL, last - prev + 1);
else 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;
}
}
/*
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
12200 KB |
Output is correct |
2 |
Correct |
4 ms |
12124 KB |
Output is correct |
3 |
Correct |
5 ms |
12120 KB |
Output is correct |
4 |
Correct |
4 ms |
12128 KB |
Output is correct |
5 |
Correct |
3 ms |
12144 KB |
Output is correct |
6 |
Correct |
2 ms |
12124 KB |
Output is correct |
7 |
Correct |
3 ms |
12124 KB |
Output is correct |
8 |
Correct |
2 ms |
12124 KB |
Output is correct |
9 |
Correct |
3 ms |
12124 KB |
Output is correct |
10 |
Correct |
3 ms |
12124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
12200 KB |
Output is correct |
2 |
Correct |
4 ms |
12124 KB |
Output is correct |
3 |
Correct |
5 ms |
12120 KB |
Output is correct |
4 |
Correct |
4 ms |
12128 KB |
Output is correct |
5 |
Correct |
3 ms |
12144 KB |
Output is correct |
6 |
Correct |
2 ms |
12124 KB |
Output is correct |
7 |
Correct |
3 ms |
12124 KB |
Output is correct |
8 |
Correct |
2 ms |
12124 KB |
Output is correct |
9 |
Correct |
3 ms |
12124 KB |
Output is correct |
10 |
Correct |
3 ms |
12124 KB |
Output is correct |
11 |
Correct |
4 ms |
12208 KB |
Output is correct |
12 |
Correct |
85 ms |
30820 KB |
Output is correct |
13 |
Correct |
2 ms |
12124 KB |
Output is correct |
14 |
Correct |
3 ms |
12124 KB |
Output is correct |
15 |
Correct |
3 ms |
12212 KB |
Output is correct |
16 |
Correct |
2 ms |
12124 KB |
Output is correct |
17 |
Correct |
163 ms |
44132 KB |
Output is correct |
18 |
Correct |
3 ms |
12200 KB |
Output is correct |
19 |
Correct |
2 ms |
12124 KB |
Output is correct |
20 |
Correct |
3 ms |
12124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
17 ms |
17132 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
12124 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
17 ms |
17132 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
12200 KB |
Output is correct |
2 |
Correct |
4 ms |
12124 KB |
Output is correct |
3 |
Correct |
5 ms |
12120 KB |
Output is correct |
4 |
Correct |
4 ms |
12128 KB |
Output is correct |
5 |
Correct |
3 ms |
12144 KB |
Output is correct |
6 |
Correct |
2 ms |
12124 KB |
Output is correct |
7 |
Correct |
3 ms |
12124 KB |
Output is correct |
8 |
Correct |
2 ms |
12124 KB |
Output is correct |
9 |
Correct |
3 ms |
12124 KB |
Output is correct |
10 |
Correct |
3 ms |
12124 KB |
Output is correct |
11 |
Correct |
4 ms |
12208 KB |
Output is correct |
12 |
Correct |
85 ms |
30820 KB |
Output is correct |
13 |
Correct |
2 ms |
12124 KB |
Output is correct |
14 |
Correct |
3 ms |
12124 KB |
Output is correct |
15 |
Correct |
3 ms |
12212 KB |
Output is correct |
16 |
Correct |
2 ms |
12124 KB |
Output is correct |
17 |
Correct |
163 ms |
44132 KB |
Output is correct |
18 |
Correct |
3 ms |
12200 KB |
Output is correct |
19 |
Correct |
2 ms |
12124 KB |
Output is correct |
20 |
Correct |
3 ms |
12124 KB |
Output is correct |
21 |
Incorrect |
17 ms |
17132 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |