Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Educational Codeforces Round 54 E. Vasya and a ...
Search
betrue12
November 13, 2018
Programming
2.5k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Educational Codeforces Round 54 E. Vasya and a Tree
ブログ解説用
betrue12
November 13, 2018
Other Decks in Programming
See All in Programming
選挙速報を多くのユーザーへ 届ける Live Activities 設計
hamayokokuririn
0
150
Intent as Code
shoppingjaws
6
1.1k
thread_parallel_with_free-threaded_Python_and_NumPy.pdf
riku_sakamoto
0
350
ハーネス設計入門 〜 基礎知識の整理から実務へのステップアップ 〜
kinopeee
12
8.8k
動作中のプログラムの中身をリアルタイムに覗く / Realtime Debugger for CSharp with Roslyn
prota
1
860
JRuby: Past, Present, and Future
headius
0
170
ゲームコントローラやキーボードのファームウェアをSwiftで書く
kishikawakatsumi
1
250
What We Talk About When We Talk About XP
m_seki
2
670
20260914 AIエージェント時代のPlatform Engineering LLM基盤とプロダクトの責務境界線
kanfab1
7
2.2k
市販E-Readerを乗っ取れ 〜Embedded Swiftで電子ペーパーガジェットを制御する〜
trickart
0
200
Workers Cache を知る
syumai
0
150
AGENTS.md Is Not Enough:Build Skills, Don't Download Them
lx_t
0
130
Featured
See All Featured
Claude Code のすすめ
schroneko
67
230k
Believing is Seeing
oripsolob
1
220
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.2k
How to Ace a Technical Interview
jacobian
281
24k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
6
1.2k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
290
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
360
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
940
Exploring anti-patterns in Rails
aemeredith
4
510
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
35
2.8k
Automating Front-end Workflow
addyosmani
1369
210k
Unsuck your backbone
ammeep
672
58k
Transcript
1 2 3 4 5 6 図のようなグラフにおいて、クエリとして v = 3,
d = 1, x = 5 の1つだけを考える。 これは図の橙色の範囲になる。
1 2 3 4 5 6 sum = 0 ans[1]
= 0 頂点1からDFSする。 sumは各頂点の値を差分更新するための値。 imos配列はimos法のように 「範囲から(下側に)出る」という処理を するための配列。 深さに対応した imos配列 クエリ v = 3, d = 1, x = 5 0 0 0 0
1 2 3 4 5 6 sum = 5 (+5)
ans[3] = 5 頂点3を訪れる。 上からの遷移でクエリの頂点 vに入った時、 imos配列に以下のような加算を行う。 (普通のimos法と同じような加算) ・vの深さに、そのクエリの加算値 xを足す。 ・「範囲から出る」深さの imos配列に -xを加算する。 その後、imos配列の値をsumに足す。 0 0 → 5 0 0 → -5 深さに対応した imos配列 クエリ v = 3, d = 1, x = 5
1 2 3 4 5 6 sum = 5 ans[5]
= 5 頂点5を訪れる。 0 5 0 -5 深さに対応した imos配列 クエリ v = 3, d = 1, x = 5
1 2 3 4 5 6 sum = 0 (-5)
ans[6] = 0 頂点6を訪れる。 範囲から出るので、sumから値を 引かなければならない。 このとき、imos配列の値を加算することで 「範囲から出る」処理を実現できる。 深さに対応した imos配列 クエリ v = 3, d = 1, x = 5 0 5 0 -5
1 2 3 4 5 6 sum = 5 (+5)
頂点5に戻る。 上に戻る際は、imos配列の値を引く。 (再びクエリの範囲内に入る) 深さに対応した imos配列 クエリ v = 3, d = 1, x = 5 0 5 0 -5
1 2 3 4 5 6 sum = 5 頂点3に戻る。
深さに対応した imos配列 クエリ v = 3, d = 1, x = 5 0 5 0 -5
1 2 3 4 5 6 sum = 5 ans[4]
= 5 頂点4を訪れる。 深さに対応した imos配列 クエリ v = 3, d = 1, x = 5 0 5 0 -5
1 2 3 4 5 6 sum = 5 頂点3に戻る。
深さに対応した imos配列 クエリ v = 3, d = 1, x = 5 0 5 0 -5
1 2 3 4 5 6 sum = 0 (-5)
頂点1に戻る。 このとき、入るときとは逆に まずsumからimos配列の値を引く。 その後、もうこのクエリの範囲には入らないので imos配列に足していた値を消す。 ※この後、頂点2を訪れる、頂点1に戻る、と続く (省略) 深さに対応した imos配列 クエリ v = 3, d = 1, x = 5 0 5 → 0 0 -5 → 0
1 2 3 4 5 6 深さに対応した imos配列 ※imos配列を使うと何が嬉しい? 1つのクエリだけだと実感できないが、
実際の問題はこんな感じで クエリが重なって入り組んでいる 「たくさんの区間をまとめて処理できる」 通常のimos法と同じように、 imos配列を使うとこれらのクエリを 同時並行的にまとめて処理できる 0 0 0 0