Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add segment tree #22

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Add segment tree #22

wants to merge 9 commits into from

Conversation

wheson
Copy link
Contributor

@wheson wheson commented Jun 26, 2018

No description provided.

@wheson wheson mentioned this pull request Jun 26, 2018
@odanado
Copy link
Member

odanado commented Jun 26, 2018

テストできるようになったと思います
古いbuildディレクトリを消して、 make build => make test していただければ

@wheson
Copy link
Contributor Author

wheson commented Jun 26, 2018

buildが変わっていないみたいでダメでした.
make testをすると

build/test/runTest
make: build/test/runTest: No such file or directory
make: *** [test] Error 1

と出ます.

@odanado
Copy link
Member

odanado commented Jun 26, 2018

make build が失敗してると思います
結果を貼り付けてもらえませんか?

@wheson
Copy link
Contributor Author

wheson commented Jun 26, 2018

bash-3.2$ make build
mkdir -p build; \
	cd build; \
	cmake ..; \
	make -j 2
-- The C compiler identification is AppleClang 9.1.0.9020039
-- The CXX compiler identification is GNU 5.5.0
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Checking whether CXX compiler has -isysroot
-- Checking whether CXX compiler has -isysroot - yes
-- Checking whether CXX compiler supports OSX deployment target flag
-- Checking whether CXX compiler supports OSX deployment target flag - yes
-- Check for working CXX compiler: /opt/local/bin/g++
-- Check for working CXX compiler: /opt/local/bin/g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PythonInterp: /Users/wheson/.anyenv/envs/pyenv/shims/python (found version "3.6.5")
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - found
-- Found Threads: TRUE
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/wheson/prog/ProconLib/build
Scanning dependencies of target ProconMath
Scanning dependencies of target gtest
[ 11%] Building CXX object lib/CMakeFiles/ProconMath.dir/Math/inverse_factorial.cpp.o
[ 22%] Building CXX object gtest-1.8.0/CMakeFiles/gtest.dir/src/gtest-all.cc.o
[ 33%] Linking CXX static library libProconMath.a
[ 33%] Built target ProconMath
[ 44%] Linking CXX static library libgtest.a
[ 44%] Built target gtest
Scanning dependencies of target gtest_main
[ 55%] Building CXX object gtest-1.8.0/CMakeFiles/gtest_main.dir/src/gtest_main.cc.o
[ 66%] Linking CXX static library libgtest_main.a
[ 66%] Built target gtest_main
Scanning dependencies of target mathTest
[ 88%] Building CXX object test/CMakeFiles/mathTest.dir/Math/test_eratos.cpp.o
[ 88%] Building CXX object test/CMakeFiles/mathTest.dir/Math/test_inverse_factorial.cpp.o
[100%] Linking CXX executable mathTest
[100%] Built target mathTest

@odanado
Copy link
Member

odanado commented Jun 26, 2018

git pull し忘れていそう

@wheson
Copy link
Contributor Author

wheson commented Jun 26, 2018

bash-3.2$ git pull origin add-segment-tree
From github.com:oit-cpt/ProconLib
 * branch            add-segment-tree -> FETCH_HEAD
Already up to date.

798aec0
これがMakefileしかcommitされていないのが気になります.

@odanado
Copy link
Member

odanado commented Jun 26, 2018

あー本当だ、申し訳ない 🙇

SegmentTree(vector<Monoid> vec, const Func f, const Monoid identityElement);
void Update(int idx, Monoid val);
Monoid Query(int a, int b, int k = 0, int l = 0,
int r = -1); // 使う時は区間[a, b)のみ指定すれば良い
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

あれここ r=-1 でよかったっけと思ったら47行目で r=n;してるのか

};

template <typename Monoid>
SegmentTree<Monoid>::SegmentTree(vector<Monoid> vec, const Func f,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

単純な疑問で、なんで第一引数にvecと受け取るようにしたか知りたいです
特に配列の大きさNを渡すだけと比べて何が違うのか

Copy link
Contributor Author

@wheson wheson Jun 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

事前に生成された配列の区間に対するQueryが高速に欲しい場合に,Update関数を用いてセグ木を作るより,配列からセグ木を作るほうが手間が省けると考えたためです.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

なるほど


template <typename Monoid>
Monoid SegmentTree<Monoid>::Query(int a, int b, int k, int l, int r) {
if (r < 0) r = n;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここは写経するときに見落としてバグりそうな気がするので、 Query(int, int, int, int, int)query(int, int, int, int, int) としてprivateに移動し、 publicに Query(int, int) という関数を新しく用意するのはどうでしょうか?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants