Skip to content

Commit 6d17235

Browse files
committed
change indentation from 4 to 2
1 parent db5b7b2 commit 6d17235

File tree

127 files changed

+4247
-4246
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+4247
-4246
lines changed

data-structures/bit.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
ll bit[N];
33

44
void add(int p, int v) {
5-
for (p += 2; p < N; p += p & -p) bit[p] += v;
5+
for (p += 2; p < N; p += p & -p) bit[p] += v;
66
}
77

88
ll query(int p) {
9-
ll r = 0;
10-
for (p += 2; p; p -= p & -p) r += bit[p];
11-
return r;
9+
ll r = 0;
10+
for (p += 2; p; p -= p & -p) r += bit[p];
11+
return r;
1212
}

data-structures/bit_binary_search.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// --- Bit Binary Search in o(log(n)) ---
22
const int M = 20
33
const int N = 1 << M
4-
4+
55
int lower_bound(int val){
6-
int ans = 0, sum = 0;
7-
for(int i = M - 1; i >= 0; i--){
8-
int x = ans + (1 << i);
9-
if(sum + bit[x] < val)
10-
ans = x, sum += bit[x];
11-
}
6+
int ans = 0, sum = 0;
7+
for(int i = M - 1; i >= 0; i--){
8+
int x = ans + (1 << i);
9+
if(sum + bit[x] < val)
10+
ans = x, sum += bit[x];
11+
}
1212

13-
return ans + 1;
13+
return ans + 1;
1414
}

data-structures/bit_range.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
struct BIT {
2-
ll b[N]={};
3-
ll sum(int x) {
4-
ll r=0;
5-
for(x+=2;x;x-=x&-x)
6-
r += b[x];
7-
return r;
8-
}
9-
void upd(int x, ll v) {
10-
for(x+=2;x<N;x+=x&-x)
11-
b[x]+=v;
12-
}
2+
ll b[N]={};
3+
ll sum(int x) {
4+
ll r=0;
5+
for(x+=2;x;x-=x&-x)
6+
r += b[x];
7+
return r;
8+
}
9+
void upd(int x, ll v) {
10+
for(x+=2;x<N;x+=x&-x)
11+
b[x]+=v;
12+
}
1313
};
1414
struct BITRange {
15-
BIT a,b;
16-
ll sum(int x) {
17-
return a.sum(x)*x+b.sum(x);
18-
}
19-
void upd(int l, int r, ll v) {
20-
a.upd(l,v), a.upd(r+1,-v);
21-
b.upd(l,-v*(l-1)), b.upd(r+1,v*r);
22-
}
15+
BIT a,b;
16+
ll sum(int x) {
17+
return a.sum(x)*x+b.sum(x);
18+
}
19+
void upd(int l, int r, ll v) {
20+
a.upd(l,v), a.upd(r+1,-v);
21+
b.upd(l,-v*(l-1)), b.upd(r+1,v*r);
22+
}
2323
};

data-structures/centroid_decomposition.cpp

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,44 @@ int n, m;
66
unordered_map<int, int> dist[N];
77

88
void dfs(int u, int p) {
9-
sz[u] = 1;
10-
for(int v : adj[u]) {
11-
if(v != p and !forb[v]) {
12-
dfs(v, u);
13-
sz[u] += sz[v];
14-
}
15-
}
9+
sz[u] = 1;
10+
for(int v : adj[u]) {
11+
if(v != p and !forb[v]) {
12+
dfs(v, u);
13+
sz[u] += sz[v];
14+
}
15+
}
1616
}
1717

1818
int find_cen(int u, int p, int qt) {
19-
for(int v : adj[u]) {
20-
if(v == p or forb[v]) continue;
21-
if(sz[v] > qt / 2) return find_cen(v, u, qt);
22-
}
23-
return u;
19+
for(int v : adj[u]) {
20+
if(v == p or forb[v]) continue;
21+
if(sz[v] > qt / 2) return find_cen(v, u, qt);
22+
}
23+
return u;
2424
}
2525

2626
void getdist(int u, int p, int cen) {
27-
for(int v : adj[u]) {
28-
if(v != p and !forb[v]) {
29-
dist[cen][v] = dist[v][cen] = dist[cen][u] + 1;
30-
getdist(v, u, cen);
31-
}
32-
}
27+
for(int v : adj[u]) {
28+
if(v != p and !forb[v]) {
29+
dist[cen][v] = dist[v][cen] = dist[cen][u] + 1;
30+
getdist(v, u, cen);
31+
}
32+
}
3333
}
3434

3535

3636
void decomp(int u, int p) {
37-
dfs(u, -1);
37+
dfs(u, -1);
3838

39-
int cen = find_cen(u, -1, sz[u]);
40-
forb[cen] = 1;
41-
par[cen] = p;
42-
dist[cen][cen] = 0;
43-
getdist(cen, -1, cen);
39+
int cen = find_cen(u, -1, sz[u]);
40+
forb[cen] = 1;
41+
par[cen] = p;
42+
dist[cen][cen] = 0;
43+
getdist(cen, -1, cen);
4444

45-
for(int v : adj[cen]) if(!forb[v])
46-
decomp(v, cen);
45+
for(int v : adj[cen]) if(!forb[v])
46+
decomp(v, cen);
4747
}
4848

4949
// main

data-structures/color_update.cpp

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,33 @@
33
// q -> number of inserts
44

55
struct ColorUpdate {
6-
struct Seg {
7-
int l, r, c;
8-
Seg(int _l = 0, int _r = 0, int _c = 0) : l(_l), r(_r), c(_c) {};
9-
bool operator<(const Seg& b) const { return l < b.l; }
10-
};
6+
struct Seg {
7+
int l, r, c;
8+
Seg(int _l = 0, int _r = 0, int _c = 0) : l(_l), r(_r), c(_c) {};
9+
bool operator<(const Seg& b) const { return l < b.l; }
10+
};
1111

12-
set<Seg> segs;
12+
set<Seg> segs;
1313

14-
void cut(int x) {
15-
auto it = segs.lower_bound({ x, 0, 0 });
16-
if (it == segs.begin()) return;
17-
it--;
18-
if (it->r == x - 1) return;
19-
Seg s = *it;
20-
segs.erase(it);
21-
segs.insert(Seg(s.l, x - 1, s.c));
22-
segs.insert(Seg(x, s.r, s.c));
23-
}
14+
void cut(int x) {
15+
auto it = segs.lower_bound({ x, 0, 0 });
16+
if (it == segs.begin()) return;
17+
it--;
18+
if (it->r == x - 1) return;
19+
Seg s = *it;
20+
segs.erase(it);
21+
segs.insert(Seg(s.l, x - 1, s.c));
22+
segs.insert(Seg(x, s.r, s.c));
23+
}
2424

25-
void add(int l, int r, int c) {
26-
cut(l), cut(r + 1);
27-
Seg s(l, r, c);
28-
auto it = segs.lower_bound(s);
29-
while (it != segs.end() and it->l <= s.r) {
30-
auto it2 = it++;
31-
segs.erase(it2);
32-
}
33-
segs.insert(s);
34-
}
25+
void add(int l, int r, int c) {
26+
cut(l), cut(r + 1);
27+
Seg s(l, r, c);
28+
auto it = segs.lower_bound(s);
29+
while (it != segs.end() and it->l <= s.r) {
30+
auto it2 = it++;
31+
segs.erase(it2);
32+
}
33+
segs.insert(s);
34+
}
3535
};

data-structures/hld-lamarca.cpp

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,48 +8,48 @@ typedef long long ll;
88
template<int N> struct Seg{
99
ll s[4*N], lazy[4*N];
1010
void build(int no = 1, int l = 0, int r = N){
11-
if(r-l==1){
12-
s[no] = 0;
13-
return;
14-
}
15-
int mid = (l+r)/2;
16-
build(2*no,l,mid);
17-
build(2*no+1,mid,r);
18-
s[no] = max(s[2*no],s[2*no+1]);
11+
if(r-l==1){
12+
s[no] = 0;
13+
return;
14+
}
15+
int mid = (l+r)/2;
16+
build(2*no,l,mid);
17+
build(2*no+1,mid,r);
18+
s[no] = max(s[2*no],s[2*no+1]);
1919
}
2020
Seg(){ //build da HLD tem de ser assim, pq chama sem os parametros
2121
build();
2222
}
2323
void updlazy(int no, int l, int r, ll x){
24-
s[no] += x;
25-
lazy[no] += x;
24+
s[no] += x;
25+
lazy[no] += x;
2626
}
2727
void pass(int no, int l, int r){
28-
int mid = (l+r)/2;
29-
updlazy(2*no,l,mid,lazy[no]);
30-
updlazy(2*no+1,mid,r,lazy[no]);
31-
lazy[no] = 0;
28+
int mid = (l+r)/2;
29+
updlazy(2*no,l,mid,lazy[no]);
30+
updlazy(2*no+1,mid,r,lazy[no]);
31+
lazy[no] = 0;
3232
}
3333
void upd(int lup, int rup, ll x, int no = 1, int l = 0, int r = N){
34-
if(rup<=l or r<=lup) return;
35-
if(lup<=l and r<=rup){
36-
updlazy(no,l,r,x);
37-
return;
38-
}
39-
pass(no,l,r);
40-
int mid = (l+r)/2;
41-
upd(lup,rup,x,2*no,l,mid);
42-
upd(lup,rup,x,2*no+1,mid,r);
43-
s[no] = max(s[2*no],s[2*no+1]);
34+
if(rup<=l or r<=lup) return;
35+
if(lup<=l and r<=rup){
36+
updlazy(no,l,r,x);
37+
return;
38+
}
39+
pass(no,l,r);
40+
int mid = (l+r)/2;
41+
upd(lup,rup,x,2*no,l,mid);
42+
upd(lup,rup,x,2*no+1,mid,r);
43+
s[no] = max(s[2*no],s[2*no+1]);
4444
}
4545
ll qry(int lq, int rq, int no = 1, int l = 0, int r = N){
46-
if(rq<=l or r<=lq) return -LLONG_MAX;
47-
if(lq<=l and r<=rq){
48-
return s[no];
49-
}
50-
pass(no,l,r);
51-
int mid = (l+r)/2;
52-
return max(qry(lq,rq,2*no,l,mid),qry(lq,rq,2*no+1,mid,r));
46+
if(rq<=l or r<=lq) return -LLONG_MAX;
47+
if(lq<=l and r<=rq){
48+
return s[no];
49+
}
50+
pass(no,l,r);
51+
int mid = (l+r)/2;
52+
return max(qry(lq,rq,2*no,l,mid),qry(lq,rq,2*no+1,mid,r));
5353
}
5454
};
5555

data-structures/hld.cpp

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,53 +6,53 @@ int chainno, chain[N], head[N], chainpos[N], chainsz[N], pos[N], arrsz;
66
int sc[N], sz[N];
77

88
void dfs(int u) {
9-
sz[u] = 1, sc[u] = 0; // nodes 1-indexed (0-ind: sc[u]=-1)
10-
for (int v : adj[u]) if (v != par[u]) {
11-
par[v] = u, h[v] = h[u]+1, dfs(v);
12-
sz[u]+=sz[v];
13-
if (sz[sc[u]] < sz[v]) sc[u] = v; // 1-indexed (0-ind: sc[u]<0 or ...)
14-
}
9+
sz[u] = 1, sc[u] = 0; // nodes 1-indexed (0-ind: sc[u]=-1)
10+
for (int v : adj[u]) if (v != par[u]) {
11+
par[v] = u, h[v] = h[u]+1, dfs(v);
12+
sz[u]+=sz[v];
13+
if (sz[sc[u]] < sz[v]) sc[u] = v; // 1-indexed (0-ind: sc[u]<0 or ...)
14+
}
1515
}
1616

1717
void hld(int u) {
18-
if (!head[chainno]) head[chainno] = u; // 1-indexed
19-
chain[u] = chainno;
20-
chainpos[u] = chainsz[chainno];
21-
chainsz[chainno]++;
22-
pos[u] = ++arrsz;
18+
if (!head[chainno]) head[chainno] = u; // 1-indexed
19+
chain[u] = chainno;
20+
chainpos[u] = chainsz[chainno];
21+
chainsz[chainno]++;
22+
pos[u] = ++arrsz;
2323

24-
if (sc[u]) hld(sc[u]);
24+
if (sc[u]) hld(sc[u]);
2525

26-
for (int v : adj[u]) if (v != par[u] and v != sc[u])
27-
chainno++, hld(v);
26+
for (int v : adj[u]) if (v != par[u] and v != sc[u])
27+
chainno++, hld(v);
2828
}
2929

3030
int lca(int u, int v) {
31-
while (chain[u] != chain[v]) {
32-
if (h[head[chain[u]]] < h[head[chain[v]]]) swap(u, v);
33-
u = par[head[chain[u]]];
34-
}
35-
if (h[u] > h[v]) swap(u, v);
36-
return u;
31+
while (chain[u] != chain[v]) {
32+
if (h[head[chain[u]]] < h[head[chain[v]]]) swap(u, v);
33+
u = par[head[chain[u]]];
34+
}
35+
if (h[u] > h[v]) swap(u, v);
36+
return u;
3737
}
3838

3939
int query_up(int u, int v) {
40-
if (u == v) return 0;
41-
int ans = -1;
42-
while (1) {
43-
if (chain[u] == chain[v]) {
44-
if (u == v) break;
45-
ans = max(ans, query(1, 1, n, chainpos[v]+1, chainpos[u]));
46-
break;
47-
}
48-
49-
ans = max(ans, query(1, 1, n, chainpos[head[chain[u]]], chainpos[u]));
50-
u = par[head[chain[u]]];
51-
}
52-
return ans;
40+
if (u == v) return 0;
41+
int ans = -1;
42+
while (1) {
43+
if (chain[u] == chain[v]) {
44+
if (u == v) break;
45+
ans = max(ans, query(1, 1, n, chainpos[v]+1, chainpos[u]));
46+
break;
47+
}
48+
49+
ans = max(ans, query(1, 1, n, chainpos[head[chain[u]]], chainpos[u]));
50+
u = par[head[chain[u]]];
51+
}
52+
return ans;
5353
}
5454

5555
int query(int u, int v) {
56-
int l = lca(u, v);
57-
return max(query_up(u, l), query_up(v, l));
56+
int l = lca(u, v);
57+
return max(query_up(u, l), query_up(v, l));
5858
}

0 commit comments

Comments
 (0)