Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0b8bc8d

Browse files
authored
Update segment_tree.md
1 parente4b572c commit0b8bc8d

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

‎src/data_structures/segment_tree.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -387,18 +387,17 @@ Instead, we can use the same idea as in the previous sections, and find the posi
387387
by moving each time to the left or the right, depending on the maximum value of the left child.
388388
Thus finding the answer in $O(\log n)$ time.
389389
390-
An example of using the following code would be get_first(1,0,n-1,5,8,14) since our segment tree starts at node 1. This would request a value greater than 14 between $[5,8]$.
391390
```{.cpp file=segment_tree_first_greater}
392-
int get_first(int v, int tl, int tr, int l, int r, intgreater_than) {
391+
int get_first(int v, int tl, int tr, int l, int r, intx) {
393392
if(tl > r || tr < l) return -1;
394-
if(t[v] <=greater_than) return -1;
393+
if(t[v] <=x) return -1;
395394
396395
if (tl== tr) return tl;
397396
398397
int tm = tl + (tr-tl)/2;
399-
int left = get_first(2*v, tl, tm, l, r,greater_than);
398+
int left = get_first(2*v, tl, tm, l, r,x);
400399
if(left != -1) return left;
401-
return get_first(2*v+1, tm+1, tr, l ,r,greater_than);
400+
return get_first(2*v+1, tm+1, tr, l ,r,x);
402401
}
403402
```
404403

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp