#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 |
8 ms |
11988 KB |
Output is correct |
2 |
Correct |
7 ms |
12064 KB |
Output is correct |
3 |
Correct |
6 ms |
11988 KB |
Output is correct |
4 |
Correct |
6 ms |
12064 KB |
Output is correct |
5 |
Correct |
6 ms |
11988 KB |
Output is correct |
6 |
Correct |
7 ms |
12028 KB |
Output is correct |
7 |
Correct |
6 ms |
11988 KB |
Output is correct |
8 |
Correct |
6 ms |
11988 KB |
Output is correct |
9 |
Correct |
6 ms |
11988 KB |
Output is correct |
10 |
Correct |
6 ms |
11988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
11988 KB |
Output is correct |
2 |
Correct |
7 ms |
12064 KB |
Output is correct |
3 |
Correct |
6 ms |
11988 KB |
Output is correct |
4 |
Correct |
6 ms |
12064 KB |
Output is correct |
5 |
Correct |
6 ms |
11988 KB |
Output is correct |
6 |
Correct |
7 ms |
12028 KB |
Output is correct |
7 |
Correct |
6 ms |
11988 KB |
Output is correct |
8 |
Correct |
6 ms |
11988 KB |
Output is correct |
9 |
Correct |
6 ms |
11988 KB |
Output is correct |
10 |
Correct |
6 ms |
11988 KB |
Output is correct |
11 |
Correct |
7 ms |
12116 KB |
Output is correct |
12 |
Correct |
148 ms |
35064 KB |
Output is correct |
13 |
Correct |
6 ms |
12048 KB |
Output is correct |
14 |
Correct |
6 ms |
12068 KB |
Output is correct |
15 |
Correct |
7 ms |
12116 KB |
Output is correct |
16 |
Correct |
7 ms |
12076 KB |
Output is correct |
17 |
Correct |
391 ms |
54928 KB |
Output is correct |
18 |
Correct |
6 ms |
12120 KB |
Output is correct |
19 |
Correct |
7 ms |
11988 KB |
Output is correct |
20 |
Correct |
6 ms |
11988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
181 ms |
40772 KB |
Output is correct |
2 |
Correct |
51 ms |
20116 KB |
Output is correct |
3 |
Correct |
43 ms |
17560 KB |
Output is correct |
4 |
Correct |
211 ms |
45036 KB |
Output is correct |
5 |
Correct |
88 ms |
30488 KB |
Output is correct |
6 |
Correct |
186 ms |
40260 KB |
Output is correct |
7 |
Correct |
9 ms |
12756 KB |
Output is correct |
8 |
Correct |
202 ms |
41032 KB |
Output is correct |
9 |
Correct |
138 ms |
30676 KB |
Output is correct |
10 |
Correct |
221 ms |
48308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
11988 KB |
Output is correct |
2 |
Correct |
7 ms |
11988 KB |
Output is correct |
3 |
Correct |
8 ms |
11988 KB |
Output is correct |
4 |
Correct |
6 ms |
11988 KB |
Output is correct |
5 |
Correct |
9 ms |
11984 KB |
Output is correct |
6 |
Correct |
8 ms |
12072 KB |
Output is correct |
7 |
Correct |
7 ms |
12116 KB |
Output is correct |
8 |
Correct |
6 ms |
12116 KB |
Output is correct |
9 |
Correct |
7 ms |
12136 KB |
Output is correct |
10 |
Correct |
7 ms |
12076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
181 ms |
40772 KB |
Output is correct |
2 |
Correct |
51 ms |
20116 KB |
Output is correct |
3 |
Correct |
43 ms |
17560 KB |
Output is correct |
4 |
Correct |
211 ms |
45036 KB |
Output is correct |
5 |
Correct |
88 ms |
30488 KB |
Output is correct |
6 |
Correct |
186 ms |
40260 KB |
Output is correct |
7 |
Correct |
9 ms |
12756 KB |
Output is correct |
8 |
Correct |
202 ms |
41032 KB |
Output is correct |
9 |
Correct |
138 ms |
30676 KB |
Output is correct |
10 |
Correct |
221 ms |
48308 KB |
Output is correct |
11 |
Correct |
7 ms |
11988 KB |
Output is correct |
12 |
Correct |
7 ms |
11988 KB |
Output is correct |
13 |
Correct |
8 ms |
11988 KB |
Output is correct |
14 |
Correct |
6 ms |
11988 KB |
Output is correct |
15 |
Correct |
9 ms |
11984 KB |
Output is correct |
16 |
Correct |
8 ms |
12072 KB |
Output is correct |
17 |
Correct |
7 ms |
12116 KB |
Output is correct |
18 |
Correct |
6 ms |
12116 KB |
Output is correct |
19 |
Correct |
7 ms |
12136 KB |
Output is correct |
20 |
Correct |
7 ms |
12076 KB |
Output is correct |
21 |
Correct |
461 ms |
51596 KB |
Output is correct |
22 |
Correct |
87 ms |
19092 KB |
Output is correct |
23 |
Correct |
54 ms |
18564 KB |
Output is correct |
24 |
Correct |
229 ms |
34816 KB |
Output is correct |
25 |
Correct |
441 ms |
51404 KB |
Output is correct |
26 |
Correct |
176 ms |
25548 KB |
Output is correct |
27 |
Correct |
72 ms |
17816 KB |
Output is correct |
28 |
Correct |
417 ms |
51404 KB |
Output is correct |
29 |
Correct |
382 ms |
51688 KB |
Output is correct |
30 |
Correct |
165 ms |
30024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
11988 KB |
Output is correct |
2 |
Correct |
7 ms |
12064 KB |
Output is correct |
3 |
Correct |
6 ms |
11988 KB |
Output is correct |
4 |
Correct |
6 ms |
12064 KB |
Output is correct |
5 |
Correct |
6 ms |
11988 KB |
Output is correct |
6 |
Correct |
7 ms |
12028 KB |
Output is correct |
7 |
Correct |
6 ms |
11988 KB |
Output is correct |
8 |
Correct |
6 ms |
11988 KB |
Output is correct |
9 |
Correct |
6 ms |
11988 KB |
Output is correct |
10 |
Correct |
6 ms |
11988 KB |
Output is correct |
11 |
Correct |
7 ms |
12116 KB |
Output is correct |
12 |
Correct |
148 ms |
35064 KB |
Output is correct |
13 |
Correct |
6 ms |
12048 KB |
Output is correct |
14 |
Correct |
6 ms |
12068 KB |
Output is correct |
15 |
Correct |
7 ms |
12116 KB |
Output is correct |
16 |
Correct |
7 ms |
12076 KB |
Output is correct |
17 |
Correct |
391 ms |
54928 KB |
Output is correct |
18 |
Correct |
6 ms |
12120 KB |
Output is correct |
19 |
Correct |
7 ms |
11988 KB |
Output is correct |
20 |
Correct |
6 ms |
11988 KB |
Output is correct |
21 |
Correct |
181 ms |
40772 KB |
Output is correct |
22 |
Correct |
51 ms |
20116 KB |
Output is correct |
23 |
Correct |
43 ms |
17560 KB |
Output is correct |
24 |
Correct |
211 ms |
45036 KB |
Output is correct |
25 |
Correct |
88 ms |
30488 KB |
Output is correct |
26 |
Correct |
186 ms |
40260 KB |
Output is correct |
27 |
Correct |
9 ms |
12756 KB |
Output is correct |
28 |
Correct |
202 ms |
41032 KB |
Output is correct |
29 |
Correct |
138 ms |
30676 KB |
Output is correct |
30 |
Correct |
221 ms |
48308 KB |
Output is correct |
31 |
Correct |
7 ms |
11988 KB |
Output is correct |
32 |
Correct |
7 ms |
11988 KB |
Output is correct |
33 |
Correct |
8 ms |
11988 KB |
Output is correct |
34 |
Correct |
6 ms |
11988 KB |
Output is correct |
35 |
Correct |
9 ms |
11984 KB |
Output is correct |
36 |
Correct |
8 ms |
12072 KB |
Output is correct |
37 |
Correct |
7 ms |
12116 KB |
Output is correct |
38 |
Correct |
6 ms |
12116 KB |
Output is correct |
39 |
Correct |
7 ms |
12136 KB |
Output is correct |
40 |
Correct |
7 ms |
12076 KB |
Output is correct |
41 |
Correct |
461 ms |
51596 KB |
Output is correct |
42 |
Correct |
87 ms |
19092 KB |
Output is correct |
43 |
Correct |
54 ms |
18564 KB |
Output is correct |
44 |
Correct |
229 ms |
34816 KB |
Output is correct |
45 |
Correct |
441 ms |
51404 KB |
Output is correct |
46 |
Correct |
176 ms |
25548 KB |
Output is correct |
47 |
Correct |
72 ms |
17816 KB |
Output is correct |
48 |
Correct |
417 ms |
51404 KB |
Output is correct |
49 |
Correct |
382 ms |
51688 KB |
Output is correct |
50 |
Correct |
165 ms |
30024 KB |
Output is correct |
51 |
Correct |
90 ms |
21900 KB |
Output is correct |
52 |
Correct |
446 ms |
57328 KB |
Output is correct |
53 |
Correct |
448 ms |
57192 KB |
Output is correct |
54 |
Correct |
123 ms |
22124 KB |
Output is correct |
55 |
Correct |
338 ms |
36128 KB |
Output is correct |
56 |
Correct |
218 ms |
32964 KB |
Output is correct |
57 |
Correct |
229 ms |
29256 KB |
Output is correct |
58 |
Correct |
449 ms |
58548 KB |
Output is correct |
59 |
Correct |
185 ms |
24944 KB |
Output is correct |
60 |
Correct |
207 ms |
28180 KB |
Output is correct |