Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Educational Codeforces Round 54 E. Vasya and a ...
Search
betrue12
November 13, 2018
Programming
0
2.3k
Educational Codeforces Round 54 E. Vasya and a Tree
ブログ解説用
betrue12
November 13, 2018
Tweet
Share
Other Decks in Programming
See All in Programming
🔨 小さなビルドシステムを作る
momeemt
4
690
Navigating Dependency Injection with Metro
zacsweers
3
2.5k
Android端末で実現するオンデバイスLLM 2025
masayukisuda
1
170
請來的 AI Agent 同事們在寫程式時,怎麼用 pytest 去除各種幻想與盲點
keitheis
0
130
OSS開発者という働き方
andpad
5
1.7k
旅行プランAIエージェント開発の裏側
ippo012
2
930
2025 年のコーディングエージェントの現在地とエンジニアの仕事の変化について
azukiazusa1
24
12k
Introducing ReActionView: A new ActionView-compatible ERB Engine @ Rails World 2025, Amsterdam
marcoroth
0
710
ファインディ株式会社におけるMCP活用とサービス開発
starfish719
0
2k
チームのテスト力を鍛える
goyoki
3
890
意外と簡単!?フロントエンドでパスキー認証を実現する WebAuthn
teamlab
PRO
2
770
Performance for Conversion! 分散トレーシングでボトルネックを 特定せよ
inetand
0
2.4k
Featured
See All Featured
GraphQLとの向き合い方2022年版
quramy
49
14k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
Raft: Consensus for Rubyists
vanstee
140
7.1k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
Automating Front-end Workflow
addyosmani
1370
200k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.4k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
23
1.4k
What’s in a name? Adding method to the madness
productmarketing
PRO
23
3.7k
Documentation Writing (for coders)
carmenintech
74
5k
jQuery: Nuts, Bolts and Bling
dougneiner
64
7.9k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
36
2.5k
Art, The Web, and Tiny UX
lynnandtonic
303
21k
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