#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
const ll mod=1e9+7;
const ll maxn=5e5+5;
const ll INF=1e18;
#define ok ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define endl '\n'
int l, r, x, u, sum[maxn], ls, st, cnt;
vi row[maxn];
map<int, int> mp, ans;
int main() {
ok
cin >> l >> r;
for(int i=1; i<=r; i++) {
cin >> x;
for(int j=0; j<x; j++) {
cin >> u;
row[i].pb(u);
sum[i]+=u;
}
}
for(int i=1; i<=r; i++) {
mp[l-sum[i]+1]++;
mp[l+1]--;
int lf=0, rg=l-sum[i]+1;
x=row[i].size();
for(int j=0; j<x-1; j++) {
lf+=row[i][j];
rg+=row[i][j];
mp[1]++;
mp[lf+1]--;
mp[rg]++;
mp[l+1]--;
}
mp[1]++;
mp[sum[i]+1]--;
ls=0; st=0;
for(auto it : mp) {
it.se+=ls;
ls=it.se;
if(it.se==x+1 && !st) {
st=it.fi;
} else if(it.se!=x+1 && st) {
ans[st]++;
ans[it.fi]--;
st=0;
}
}
mp.clear();
}
ls=0; st=0;
for(auto it : ans) {
it.se+=ls;
ls=it.se;
if(it.se>0 && !st) {
st=it.fi;
} else if(it.se<=0 && st) {
cnt+=it.fi-st;
st=0;
}
}
cout << cnt;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Correct |
6 ms |
11988 KB |
Output is correct |
3 |
Correct |
7 ms |
12012 KB |
Output is correct |
4 |
Correct |
6 ms |
11988 KB |
Output is correct |
5 |
Correct |
6 ms |
11988 KB |
Output is correct |
6 |
Correct |
6 ms |
12068 KB |
Output is correct |
7 |
Correct |
6 ms |
11984 KB |
Output is correct |
8 |
Correct |
7 ms |
12064 KB |
Output is correct |
9 |
Correct |
6 ms |
11988 KB |
Output is correct |
10 |
Correct |
6 ms |
11940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Correct |
6 ms |
11988 KB |
Output is correct |
3 |
Correct |
7 ms |
12012 KB |
Output is correct |
4 |
Correct |
6 ms |
11988 KB |
Output is correct |
5 |
Correct |
6 ms |
11988 KB |
Output is correct |
6 |
Correct |
6 ms |
12068 KB |
Output is correct |
7 |
Correct |
6 ms |
11984 KB |
Output is correct |
8 |
Correct |
7 ms |
12064 KB |
Output is correct |
9 |
Correct |
6 ms |
11988 KB |
Output is correct |
10 |
Correct |
6 ms |
11940 KB |
Output is correct |
11 |
Correct |
7 ms |
12116 KB |
Output is correct |
12 |
Correct |
139 ms |
29308 KB |
Output is correct |
13 |
Correct |
6 ms |
11968 KB |
Output is correct |
14 |
Correct |
6 ms |
11988 KB |
Output is correct |
15 |
Correct |
7 ms |
12116 KB |
Output is correct |
16 |
Correct |
7 ms |
12116 KB |
Output is correct |
17 |
Correct |
403 ms |
49068 KB |
Output is correct |
18 |
Correct |
6 ms |
11956 KB |
Output is correct |
19 |
Correct |
7 ms |
11988 KB |
Output is correct |
20 |
Correct |
7 ms |
11988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
182 ms |
40092 KB |
Output is correct |
2 |
Correct |
42 ms |
20004 KB |
Output is correct |
3 |
Correct |
43 ms |
17292 KB |
Output is correct |
4 |
Correct |
201 ms |
44416 KB |
Output is correct |
5 |
Correct |
100 ms |
30212 KB |
Output is correct |
6 |
Correct |
183 ms |
39440 KB |
Output is correct |
7 |
Correct |
9 ms |
12728 KB |
Output is correct |
8 |
Correct |
204 ms |
40132 KB |
Output is correct |
9 |
Correct |
134 ms |
30200 KB |
Output is correct |
10 |
Correct |
216 ms |
47564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Correct |
6 ms |
11988 KB |
Output is correct |
3 |
Correct |
6 ms |
11988 KB |
Output is correct |
4 |
Correct |
6 ms |
11988 KB |
Output is correct |
5 |
Correct |
6 ms |
12080 KB |
Output is correct |
6 |
Correct |
6 ms |
11988 KB |
Output is correct |
7 |
Correct |
6 ms |
12116 KB |
Output is correct |
8 |
Correct |
7 ms |
12056 KB |
Output is correct |
9 |
Correct |
7 ms |
12116 KB |
Output is correct |
10 |
Correct |
7 ms |
11988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
182 ms |
40092 KB |
Output is correct |
2 |
Correct |
42 ms |
20004 KB |
Output is correct |
3 |
Correct |
43 ms |
17292 KB |
Output is correct |
4 |
Correct |
201 ms |
44416 KB |
Output is correct |
5 |
Correct |
100 ms |
30212 KB |
Output is correct |
6 |
Correct |
183 ms |
39440 KB |
Output is correct |
7 |
Correct |
9 ms |
12728 KB |
Output is correct |
8 |
Correct |
204 ms |
40132 KB |
Output is correct |
9 |
Correct |
134 ms |
30200 KB |
Output is correct |
10 |
Correct |
216 ms |
47564 KB |
Output is correct |
11 |
Correct |
6 ms |
11988 KB |
Output is correct |
12 |
Correct |
6 ms |
11988 KB |
Output is correct |
13 |
Correct |
6 ms |
11988 KB |
Output is correct |
14 |
Correct |
6 ms |
11988 KB |
Output is correct |
15 |
Correct |
6 ms |
12080 KB |
Output is correct |
16 |
Correct |
6 ms |
11988 KB |
Output is correct |
17 |
Correct |
6 ms |
12116 KB |
Output is correct |
18 |
Correct |
7 ms |
12056 KB |
Output is correct |
19 |
Correct |
7 ms |
12116 KB |
Output is correct |
20 |
Correct |
7 ms |
11988 KB |
Output is correct |
21 |
Correct |
431 ms |
47220 KB |
Output is correct |
22 |
Correct |
81 ms |
18300 KB |
Output is correct |
23 |
Correct |
56 ms |
18396 KB |
Output is correct |
24 |
Correct |
229 ms |
33960 KB |
Output is correct |
25 |
Correct |
386 ms |
47436 KB |
Output is correct |
26 |
Correct |
184 ms |
24700 KB |
Output is correct |
27 |
Correct |
68 ms |
17312 KB |
Output is correct |
28 |
Correct |
415 ms |
47444 KB |
Output is correct |
29 |
Correct |
409 ms |
47692 KB |
Output is correct |
30 |
Correct |
179 ms |
29456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Correct |
6 ms |
11988 KB |
Output is correct |
3 |
Correct |
7 ms |
12012 KB |
Output is correct |
4 |
Correct |
6 ms |
11988 KB |
Output is correct |
5 |
Correct |
6 ms |
11988 KB |
Output is correct |
6 |
Correct |
6 ms |
12068 KB |
Output is correct |
7 |
Correct |
6 ms |
11984 KB |
Output is correct |
8 |
Correct |
7 ms |
12064 KB |
Output is correct |
9 |
Correct |
6 ms |
11988 KB |
Output is correct |
10 |
Correct |
6 ms |
11940 KB |
Output is correct |
11 |
Correct |
7 ms |
12116 KB |
Output is correct |
12 |
Correct |
139 ms |
29308 KB |
Output is correct |
13 |
Correct |
6 ms |
11968 KB |
Output is correct |
14 |
Correct |
6 ms |
11988 KB |
Output is correct |
15 |
Correct |
7 ms |
12116 KB |
Output is correct |
16 |
Correct |
7 ms |
12116 KB |
Output is correct |
17 |
Correct |
403 ms |
49068 KB |
Output is correct |
18 |
Correct |
6 ms |
11956 KB |
Output is correct |
19 |
Correct |
7 ms |
11988 KB |
Output is correct |
20 |
Correct |
7 ms |
11988 KB |
Output is correct |
21 |
Correct |
182 ms |
40092 KB |
Output is correct |
22 |
Correct |
42 ms |
20004 KB |
Output is correct |
23 |
Correct |
43 ms |
17292 KB |
Output is correct |
24 |
Correct |
201 ms |
44416 KB |
Output is correct |
25 |
Correct |
100 ms |
30212 KB |
Output is correct |
26 |
Correct |
183 ms |
39440 KB |
Output is correct |
27 |
Correct |
9 ms |
12728 KB |
Output is correct |
28 |
Correct |
204 ms |
40132 KB |
Output is correct |
29 |
Correct |
134 ms |
30200 KB |
Output is correct |
30 |
Correct |
216 ms |
47564 KB |
Output is correct |
31 |
Correct |
6 ms |
11988 KB |
Output is correct |
32 |
Correct |
6 ms |
11988 KB |
Output is correct |
33 |
Correct |
6 ms |
11988 KB |
Output is correct |
34 |
Correct |
6 ms |
11988 KB |
Output is correct |
35 |
Correct |
6 ms |
12080 KB |
Output is correct |
36 |
Correct |
6 ms |
11988 KB |
Output is correct |
37 |
Correct |
6 ms |
12116 KB |
Output is correct |
38 |
Correct |
7 ms |
12056 KB |
Output is correct |
39 |
Correct |
7 ms |
12116 KB |
Output is correct |
40 |
Correct |
7 ms |
11988 KB |
Output is correct |
41 |
Correct |
431 ms |
47220 KB |
Output is correct |
42 |
Correct |
81 ms |
18300 KB |
Output is correct |
43 |
Correct |
56 ms |
18396 KB |
Output is correct |
44 |
Correct |
229 ms |
33960 KB |
Output is correct |
45 |
Correct |
386 ms |
47436 KB |
Output is correct |
46 |
Correct |
184 ms |
24700 KB |
Output is correct |
47 |
Correct |
68 ms |
17312 KB |
Output is correct |
48 |
Correct |
415 ms |
47444 KB |
Output is correct |
49 |
Correct |
409 ms |
47692 KB |
Output is correct |
50 |
Correct |
179 ms |
29456 KB |
Output is correct |
51 |
Correct |
72 ms |
21300 KB |
Output is correct |
52 |
Correct |
418 ms |
51820 KB |
Output is correct |
53 |
Correct |
424 ms |
51916 KB |
Output is correct |
54 |
Correct |
119 ms |
20860 KB |
Output is correct |
55 |
Correct |
356 ms |
33356 KB |
Output is correct |
56 |
Correct |
199 ms |
31692 KB |
Output is correct |
57 |
Correct |
236 ms |
27424 KB |
Output is correct |
58 |
Correct |
439 ms |
52980 KB |
Output is correct |
59 |
Correct |
157 ms |
23756 KB |
Output is correct |
60 |
Correct |
236 ms |
26276 KB |
Output is correct |