Skip to content

Commit

Permalink
updated some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Asad committed May 14, 2023
1 parent 04498ce commit 6c5f57c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 22 deletions.
4 changes: 2 additions & 2 deletions data-structure/dsu.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// code 1
const int MX = 2e5;
int dsu[MX+5], sz[MX+5];
const int N = 2e5;
int dsu[N+5], sz[N+5];
// sz[] is initialized by value 1;
// dsu[] if initialized by dsu[K] = K

Expand Down
9 changes: 6 additions & 3 deletions data-structure/lca.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const int N= 1e5+5,LOG= 20;
int depth[N],up[N][LOG];
const int N= 1e5+5, LOG= 20;
int depth[N+5], up[N+5][LOG];
vector<int> v[N];

void dfs(int pos,int pre)
{
for(auto it:v[pos])
Expand All @@ -14,7 +15,6 @@ void dfs(int pos,int pre)
}
dfs(it,pos);
}
return ;
}
int kthancestor(int pos,int k)
{
Expand Down Expand Up @@ -47,3 +47,6 @@ int get_lca(int a, int b)
return up[a][0];
}


// initialize with ...
up[root][0] = root;
2 changes: 1 addition & 1 deletion data-structure/segment-tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void update(int at, int l, int r, int idx, int num)
int query(int at, int l, int r, int L, int R)
{
// query from l to r.
if(R < l || L > r) return 0;
if(r < l || R < l || L > r) return 0;
if(L <= l && r <= R) return sum[at];

int mid = (l+r)/2;
Expand Down
32 changes: 16 additions & 16 deletions geometry/convex-hull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,37 @@ bool ccw(pt a, pt b, pt c, bool include_collinear) {
return o > 0 || (include_collinear && o == 0);
}

void convex_hull(vector<pt>& a, bool include_collinear = false) {
if (a.size() == 1)
void convex_hull(vector<pt>& ara, bool include_collinear = false) {
if (ara.size() == 1)
return;

sort(a.begin(), a.end(), [](pt a, pt b) {
sort(ara.begin(), ara.end(), [](pt a, pt b) {
return make_pair(a.x, a.y) < make_pair(b.x, b.y);
});
pt p1 = a[0], p2 = a.back();
pt p1 = ara[0], p2 = ara.back();
vector<pt> up, down;
up.push_back(p1);
down.push_back(p1);
for (int i = 1; i < (int)a.size(); i++) {
if (i == a.size() - 1 || cw(p1, a[i], p2, include_collinear)) {
while (up.size() >= 2 && !cw(up[up.size()-2], up[up.size()-1], a[i], include_collinear))
for (int i = 1; i < (int)ara.size(); i++) {
if (i == ara.size() - 1 || cw(p1, ara[i], p2, include_collinear)) {
while (up.size() >= 2 && !cw(up[up.size()-2], up[up.size()-1], ara[i], include_collinear))
up.pop_back();
up.push_back(a[i]);
up.push_back(ara[i]);
}
if (i == a.size() - 1 || ccw(p1, a[i], p2, include_collinear)) {
while (down.size() >= 2 && !ccw(down[down.size()-2], down[down.size()-1], a[i], include_collinear))
if (i == ara.size() - 1 || ccw(p1, ara[i], p2, include_collinear)) {
while (down.size() >= 2 && !ccw(down[down.size()-2], down[down.size()-1], ara[i], include_collinear))
down.pop_back();
down.push_back(a[i]);
down.push_back(ara[i]);
}
}

if (include_collinear && up.size() == a.size()) {
reverse(a.begin(), a.end());
if (include_collinear && up.size() == ara.size()) {
reverse(ara.begin(), ara.end());
return;
}
a.clear();
ara.clear();
for (int i = 0; i < (int)up.size(); i++)
a.push_back(up[i]);
ara.push_back(up[i]);
for (int i = down.size() - 2; i > 0; i--)
a.push_back(down[i]);
ara.push_back(down[i]);
}

0 comments on commit 6c5f57c

Please sign in to comment.