Skip to content
Snippets Groups Projects
Commit 8c2ff920 authored by Bruno Freitas Tissei's avatar Bruno Freitas Tissei
Browse files

Fix ternary search

parent 2ecb2a98
No related branches found
No related tags found
No related merge requests found
...@@ -20,8 +20,8 @@ double ternary_search(double l, double r) { ...@@ -20,8 +20,8 @@ double ternary_search(double l, double r) {
if (fabs(r - l) < EPS) if (fabs(r - l) < EPS)
return (l + r) / 2.0; return (l + r) / 2.0;
lt = l + (r - l) / 3.0; lt = (r - l) / 3.0 + l;
rt = r - (r - l) / 3.0; rt = ((r - l) * 2.0) / 3.0 + l;
// < | minimum of f // < | minimum of f
// > | maximum of f // > | maximum of f
......
...@@ -12,8 +12,8 @@ using namespace std; ...@@ -12,8 +12,8 @@ using namespace std;
typedef unsigned long long ll; typedef unsigned long long ll;
typedef pair<ll,ll> ii; typedef pair<ll,ll> ii;
vector<int> t1[MAX], t2[MAX];
ll hsh[MAX]; ll hsh[MAX];
vector<int> t1[MAX], t2[MAX];
unordered_map<ll, int> M; unordered_map<ll, int> M;
ll ans = 0, tot = 0; ll ans = 0, tot = 0;
......
...@@ -11,9 +11,9 @@ int tree[MAXN][MAXM]; ...@@ -11,9 +11,9 @@ int tree[MAXN][MAXM];
// Perform query in array (tree) in the (idx,idy) position // Perform query in array (tree) in the (idx,idy) position
int query(int idx, int idy) { int query(int idx, int idy) {
int sum = 0, m; int sum = 0;
for (; idx > 0; idx -= (idx & -idx)) for (; idx > 0; idx -= (idx & -idx))
for (m = idy; m > 0; m -= (m & -m)) for (int m = idy; m > 0; m -= (m & -m))
sum += tree[idx][m]; sum += tree[idx][m];
return sum; return sum;
...@@ -21,8 +21,7 @@ int query(int idx, int idy) { ...@@ -21,8 +21,7 @@ int query(int idx, int idy) {
// Add a value (val) to a single position (idx,idy) in the array (tree). // Add a value (val) to a single position (idx,idy) in the array (tree).
void update(int idx, int idy, int val) { void update(int idx, int idy, int val) {
int m;
for (; idx <= MAXN; idx += (idx & -idx)) for (; idx <= MAXN; idx += (idx & -idx))
for (m = idy; m <= MAXM; m += (m & -m)) for (int m = idy; m <= MAXM; m += (m & -m))
tree[idx][m] += val; tree[idx][m] += val;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment