Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
competitive
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Harbor Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bruno Freitas Tissei
competitive
Commits
8c2ff920
Commit
8c2ff920
authored
7 years ago
by
Bruno Freitas Tissei
Browse files
Options
Downloads
Patches
Plain Diff
Fix ternary search
Signed-off-by:
Bruno Freitas Tissei
<
bft15@inf.ufpr.br
>
parent
2ecb2a98
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
paradigm/ternary_search.cpp
+2
-2
2 additions, 2 deletions
paradigm/ternary_search.cpp
problems/trees_partition.cpp
+1
-1
1 addition, 1 deletion
problems/trees_partition.cpp
structure/bit2d.cpp
+3
-4
3 additions, 4 deletions
structure/bit2d.cpp
with
6 additions
and
7 deletions
paradigm/ternary_search.cpp
+
2
−
2
View file @
8c2ff920
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
problems/trees_partition.cpp
+
1
−
1
View file @
8c2ff920
...
@@ -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
;
...
...
This diff is collapsed.
Click to expand it.
structure/bit2d.cpp
+
3
−
4
View file @
8c2ff920
...
@@ -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
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment