#include <bits/stdc++.h>
using namespace std;
#define pii pair<ll,ll>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define freeopen freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define mod 998244353
#define pb push_back
#define mk make_pair
#define ll long long
#define foor(x,vec) for(auto x:vec ){cout<<x<<" ";}
#define fi first
#define se second
#define MAXN 500069
#define lld long double
#define cha ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ffl fflush(stdout)
#define sst string
#define pii pair<ll,ll>
ll mvx[]={0,0,-1,1};
ll mvy[]={1,-1,0,0};
ll n,q;
ll k[MAXN];
vector<ll> b[MAXN];
ll vis[MAXN];
ll ps[MAXN],sf[MAXN];
void solve(){
cin>>n>>q;
REP(i,0,q-1){
cin>>k[i];
REP(j,0,k[i]-1){
ll x;
cin>>x;
b[i].pb(x);
}
}
ll ans=0;
vector <pair<ll,ll>> vec;
REP(i,0,q-1){
REP(j,0,k[i]){
ps[j]=0;
sf[j]=0;
}
for(ll j=0;j<k[i];j++){
ps[j]=ps[j-1]+b[i][j];
}
for(ll j=k[i]-1;j>=0;j--){
sf[j]=sf[j+1]+b[i][j];
}
REP(j,0,k[i]-1){
ll r=n-sf[j+1]-1;
ll l=ps[j-1]+1;
if(j-1<0)l=1;
ll len=r-l+1;
if(len-2*(len-b[i][j])>0){
ll nl=r-b[i][j]+1;
ll nr=l+b[i][j]-2;
if(nl<=nr)
vec.pb({nl,nr});
}
}
}
sort(vec.begin(),vec.end());
ll i=0;
while(i<vec.size()){
ll ln=vec[i].fi;
ll rn=vec[i].se;
ll idx=i+1;
while(idx<vec.size()){
if(vec[idx].fi==ln){
rn=max(rn,vec[idx].se);
idx++;
}
else{
break;
}
}
i=idx;
ans+=max((rn-ln+1),(ll)0);
while(idx<vec.size() && vec[idx].fi<ln){
i++;
}
}
cout<<ans<<endl;
}
int main(){
cha
ll tc=1;
// cin>>tc;
while(tc--){
solve();
}
}
Compilation message
lasers.cpp: In function 'void solve()':
lasers.cpp:67:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | while(i<vec.size()){
| ~^~~~~~~~~~~
lasers.cpp:71:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | while(idx<vec.size()){
| ~~~^~~~~~~~~~~
lasers.cpp:82:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
82 | while(idx<vec.size() && vec[idx].fi<ln){
| ~~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
16732 KB |
Output is correct |
2 |
Correct |
3 ms |
16836 KB |
Output is correct |
3 |
Correct |
2 ms |
16732 KB |
Output is correct |
4 |
Correct |
2 ms |
16836 KB |
Output is correct |
5 |
Correct |
3 ms |
16732 KB |
Output is correct |
6 |
Correct |
2 ms |
16732 KB |
Output is correct |
7 |
Correct |
2 ms |
16744 KB |
Output is correct |
8 |
Correct |
2 ms |
16732 KB |
Output is correct |
9 |
Correct |
2 ms |
16732 KB |
Output is correct |
10 |
Correct |
2 ms |
16732 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
16732 KB |
Output is correct |
2 |
Correct |
3 ms |
16836 KB |
Output is correct |
3 |
Correct |
2 ms |
16732 KB |
Output is correct |
4 |
Correct |
2 ms |
16836 KB |
Output is correct |
5 |
Correct |
3 ms |
16732 KB |
Output is correct |
6 |
Correct |
2 ms |
16732 KB |
Output is correct |
7 |
Correct |
2 ms |
16744 KB |
Output is correct |
8 |
Correct |
2 ms |
16732 KB |
Output is correct |
9 |
Correct |
2 ms |
16732 KB |
Output is correct |
10 |
Correct |
2 ms |
16732 KB |
Output is correct |
11 |
Incorrect |
3 ms |
16732 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
34 ms |
27572 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
16732 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
34 ms |
27572 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
16732 KB |
Output is correct |
2 |
Correct |
3 ms |
16836 KB |
Output is correct |
3 |
Correct |
2 ms |
16732 KB |
Output is correct |
4 |
Correct |
2 ms |
16836 KB |
Output is correct |
5 |
Correct |
3 ms |
16732 KB |
Output is correct |
6 |
Correct |
2 ms |
16732 KB |
Output is correct |
7 |
Correct |
2 ms |
16744 KB |
Output is correct |
8 |
Correct |
2 ms |
16732 KB |
Output is correct |
9 |
Correct |
2 ms |
16732 KB |
Output is correct |
10 |
Correct |
2 ms |
16732 KB |
Output is correct |
11 |
Incorrect |
3 ms |
16732 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |