#include <bits/stdc++.h>
using namespace std;
struct node{
int val;
int left=-1;
int right=-1;
};
class lazySparseSegTree{
private:
int cr = 1;
int n;
node *st;
int *laz;
node def;
int no;
public:
lazySparseSegTree(int siz, int nodes){
st = new node[nodes];
laz = new int[nodes];
def.val=0;
def.left=-1;
def.right=-1;
fill(st,st+nodes,def);
fill(laz,laz+nodes,0);
n=siz-1;
no=nodes;
}
void makeKids(int ind){
if(st[ind].left==-1){
st[ind].left=cr++;
}
if(st[ind].right==-1){
st[ind].right=cr++;
}
assert(cr<no);
}
void pushdown(int ind, int l, int r){
if(laz[ind]==0){
return;
}
if(l==r){
st[ind].val=laz[ind]*(r-l+1);
return;
}
makeKids(ind);
int mid = (l+r)/2;
laz[st[ind].left]=laz[ind];
laz[st[ind].right]=laz[ind];
st[st[ind].left].val=laz[ind]*(mid-l+1);
st[st[ind].right].val=laz[ind]*(r-mid);
laz[ind]=0;
}
void realUpdate(int l, int r, int s, int e, int val, int ind){
if(r<s||l>e){
return;
}
if(s<=l&&r<=e){
laz[ind]=val;
st[ind].val=(r-l+1)*val;
return;
}
int mid = (l+r)/2;
pushdown(ind,l,r);
makeKids(ind);
realUpdate(l,mid,s,e,val,st[ind].left);
realUpdate(mid+1,r,s,e,val,st[ind].right);
st[ind].val=st[st[ind].left].val+st[st[ind].right].val;
}
void update(int l, int r, int val){
realUpdate(0,n,l,r,val,0);
}
int realQuery(int l, int r, int s, int e, int ind){
if(r<s||l>e){
return 0;
}
pushdown(ind,l,r);
if(s<=l&&r<=e){
return st[ind].val;
}
int mid = (l+r)/2;
makeKids(ind);
return realQuery(l,mid,s,e,st[ind].left)+realQuery(mid+1,r,s,e,st[ind].right);
}
int query(int l, int r){
return realQuery(0,n,l,r,0);
}
};
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int l,r;
cin >> l >> r;
vector<int>walls[r];
lazySparseSegTree lsst(l,1e7);
int sums[r];
for(int i = 0;i<r;i++){
int x;
cin >> x;
sums[i]=0;
for(int j = 0;j<x;j++){
int c;
cin >> c;
sums[i]+=c;
walls[i].push_back(c);
}
}
for(int i = 0;i<r;i++){
int curl=0;
for(int w : walls[i]){
int lef = sums[i]-curl;
lef=l-lef;
int right = curl+w-1;
curl+=w;
if(right<lef){
continue;
}
lsst.update(lef,right,1);
}
}
cout << lsst.query(0,l-1);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
156776 KB |
Output is correct |
2 |
Correct |
29 ms |
157008 KB |
Output is correct |
3 |
Correct |
31 ms |
156828 KB |
Output is correct |
4 |
Correct |
33 ms |
157008 KB |
Output is correct |
5 |
Correct |
31 ms |
156792 KB |
Output is correct |
6 |
Correct |
39 ms |
157008 KB |
Output is correct |
7 |
Correct |
40 ms |
156776 KB |
Output is correct |
8 |
Correct |
34 ms |
157008 KB |
Output is correct |
9 |
Correct |
29 ms |
157008 KB |
Output is correct |
10 |
Correct |
31 ms |
156788 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
156776 KB |
Output is correct |
2 |
Correct |
29 ms |
157008 KB |
Output is correct |
3 |
Correct |
31 ms |
156828 KB |
Output is correct |
4 |
Correct |
33 ms |
157008 KB |
Output is correct |
5 |
Correct |
31 ms |
156792 KB |
Output is correct |
6 |
Correct |
39 ms |
157008 KB |
Output is correct |
7 |
Correct |
40 ms |
156776 KB |
Output is correct |
8 |
Correct |
34 ms |
157008 KB |
Output is correct |
9 |
Correct |
29 ms |
157008 KB |
Output is correct |
10 |
Correct |
31 ms |
156788 KB |
Output is correct |
11 |
Correct |
29 ms |
157000 KB |
Output is correct |
12 |
Correct |
123 ms |
185672 KB |
Output is correct |
13 |
Correct |
35 ms |
156780 KB |
Output is correct |
14 |
Correct |
30 ms |
157008 KB |
Output is correct |
15 |
Correct |
29 ms |
157008 KB |
Output is correct |
16 |
Correct |
28 ms |
157068 KB |
Output is correct |
17 |
Correct |
431 ms |
186232 KB |
Output is correct |
18 |
Correct |
28 ms |
157008 KB |
Output is correct |
19 |
Correct |
32 ms |
156792 KB |
Output is correct |
20 |
Correct |
28 ms |
157000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
98 ms |
159172 KB |
Output is correct |
2 |
Correct |
49 ms |
157304 KB |
Output is correct |
3 |
Correct |
36 ms |
157396 KB |
Output is correct |
4 |
Correct |
96 ms |
158540 KB |
Output is correct |
5 |
Correct |
52 ms |
158124 KB |
Output is correct |
6 |
Correct |
56 ms |
160008 KB |
Output is correct |
7 |
Correct |
29 ms |
157000 KB |
Output is correct |
8 |
Correct |
71 ms |
160880 KB |
Output is correct |
9 |
Correct |
70 ms |
157904 KB |
Output is correct |
10 |
Correct |
113 ms |
158924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
156940 KB |
Output is correct |
2 |
Correct |
28 ms |
157008 KB |
Output is correct |
3 |
Correct |
31 ms |
156776 KB |
Output is correct |
4 |
Correct |
32 ms |
157020 KB |
Output is correct |
5 |
Correct |
29 ms |
157020 KB |
Output is correct |
6 |
Correct |
28 ms |
156784 KB |
Output is correct |
7 |
Correct |
29 ms |
157008 KB |
Output is correct |
8 |
Correct |
41 ms |
157064 KB |
Output is correct |
9 |
Correct |
33 ms |
156840 KB |
Output is correct |
10 |
Correct |
29 ms |
156816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
98 ms |
159172 KB |
Output is correct |
2 |
Correct |
49 ms |
157304 KB |
Output is correct |
3 |
Correct |
36 ms |
157396 KB |
Output is correct |
4 |
Correct |
96 ms |
158540 KB |
Output is correct |
5 |
Correct |
52 ms |
158124 KB |
Output is correct |
6 |
Correct |
56 ms |
160008 KB |
Output is correct |
7 |
Correct |
29 ms |
157000 KB |
Output is correct |
8 |
Correct |
71 ms |
160880 KB |
Output is correct |
9 |
Correct |
70 ms |
157904 KB |
Output is correct |
10 |
Correct |
113 ms |
158924 KB |
Output is correct |
11 |
Correct |
29 ms |
156940 KB |
Output is correct |
12 |
Correct |
28 ms |
157008 KB |
Output is correct |
13 |
Correct |
31 ms |
156776 KB |
Output is correct |
14 |
Correct |
32 ms |
157020 KB |
Output is correct |
15 |
Correct |
29 ms |
157020 KB |
Output is correct |
16 |
Correct |
28 ms |
156784 KB |
Output is correct |
17 |
Correct |
29 ms |
157008 KB |
Output is correct |
18 |
Correct |
41 ms |
157064 KB |
Output is correct |
19 |
Correct |
33 ms |
156840 KB |
Output is correct |
20 |
Correct |
29 ms |
156816 KB |
Output is correct |
21 |
Correct |
332 ms |
186132 KB |
Output is correct |
22 |
Correct |
75 ms |
158196 KB |
Output is correct |
23 |
Correct |
55 ms |
157780 KB |
Output is correct |
24 |
Correct |
113 ms |
160124 KB |
Output is correct |
25 |
Correct |
354 ms |
190284 KB |
Output is correct |
26 |
Correct |
130 ms |
159632 KB |
Output is correct |
27 |
Correct |
81 ms |
158028 KB |
Output is correct |
28 |
Correct |
346 ms |
190312 KB |
Output is correct |
29 |
Correct |
342 ms |
190284 KB |
Output is correct |
30 |
Correct |
80 ms |
159532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
156776 KB |
Output is correct |
2 |
Correct |
29 ms |
157008 KB |
Output is correct |
3 |
Correct |
31 ms |
156828 KB |
Output is correct |
4 |
Correct |
33 ms |
157008 KB |
Output is correct |
5 |
Correct |
31 ms |
156792 KB |
Output is correct |
6 |
Correct |
39 ms |
157008 KB |
Output is correct |
7 |
Correct |
40 ms |
156776 KB |
Output is correct |
8 |
Correct |
34 ms |
157008 KB |
Output is correct |
9 |
Correct |
29 ms |
157008 KB |
Output is correct |
10 |
Correct |
31 ms |
156788 KB |
Output is correct |
11 |
Correct |
29 ms |
157000 KB |
Output is correct |
12 |
Correct |
123 ms |
185672 KB |
Output is correct |
13 |
Correct |
35 ms |
156780 KB |
Output is correct |
14 |
Correct |
30 ms |
157008 KB |
Output is correct |
15 |
Correct |
29 ms |
157008 KB |
Output is correct |
16 |
Correct |
28 ms |
157068 KB |
Output is correct |
17 |
Correct |
431 ms |
186232 KB |
Output is correct |
18 |
Correct |
28 ms |
157008 KB |
Output is correct |
19 |
Correct |
32 ms |
156792 KB |
Output is correct |
20 |
Correct |
28 ms |
157000 KB |
Output is correct |
21 |
Correct |
98 ms |
159172 KB |
Output is correct |
22 |
Correct |
49 ms |
157304 KB |
Output is correct |
23 |
Correct |
36 ms |
157396 KB |
Output is correct |
24 |
Correct |
96 ms |
158540 KB |
Output is correct |
25 |
Correct |
52 ms |
158124 KB |
Output is correct |
26 |
Correct |
56 ms |
160008 KB |
Output is correct |
27 |
Correct |
29 ms |
157000 KB |
Output is correct |
28 |
Correct |
71 ms |
160880 KB |
Output is correct |
29 |
Correct |
70 ms |
157904 KB |
Output is correct |
30 |
Correct |
113 ms |
158924 KB |
Output is correct |
31 |
Correct |
29 ms |
156940 KB |
Output is correct |
32 |
Correct |
28 ms |
157008 KB |
Output is correct |
33 |
Correct |
31 ms |
156776 KB |
Output is correct |
34 |
Correct |
32 ms |
157020 KB |
Output is correct |
35 |
Correct |
29 ms |
157020 KB |
Output is correct |
36 |
Correct |
28 ms |
156784 KB |
Output is correct |
37 |
Correct |
29 ms |
157008 KB |
Output is correct |
38 |
Correct |
41 ms |
157064 KB |
Output is correct |
39 |
Correct |
33 ms |
156840 KB |
Output is correct |
40 |
Correct |
29 ms |
156816 KB |
Output is correct |
41 |
Correct |
332 ms |
186132 KB |
Output is correct |
42 |
Correct |
75 ms |
158196 KB |
Output is correct |
43 |
Correct |
55 ms |
157780 KB |
Output is correct |
44 |
Correct |
113 ms |
160124 KB |
Output is correct |
45 |
Correct |
354 ms |
190284 KB |
Output is correct |
46 |
Correct |
130 ms |
159632 KB |
Output is correct |
47 |
Correct |
81 ms |
158028 KB |
Output is correct |
48 |
Correct |
346 ms |
190312 KB |
Output is correct |
49 |
Correct |
342 ms |
190284 KB |
Output is correct |
50 |
Correct |
80 ms |
159532 KB |
Output is correct |
51 |
Correct |
83 ms |
158292 KB |
Output is correct |
52 |
Correct |
465 ms |
191524 KB |
Output is correct |
53 |
Correct |
452 ms |
191308 KB |
Output is correct |
54 |
Correct |
125 ms |
159308 KB |
Output is correct |
55 |
Correct |
288 ms |
162812 KB |
Output is correct |
56 |
Correct |
180 ms |
159960 KB |
Output is correct |
57 |
Correct |
227 ms |
160752 KB |
Output is correct |
58 |
Correct |
530 ms |
191808 KB |
Output is correct |
59 |
Correct |
165 ms |
159448 KB |
Output is correct |
60 |
Correct |
221 ms |
160844 KB |
Output is correct |