Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
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
開発に寄りそう自動テストの実現
goyoki
1
910
C-Shared Buildで突破するAI Agent バックテストの壁
po3rin
0
380
バックエンドエンジニアによる Amebaブログ K8s 基盤への CronJobの導入・運用経験
sunabig
0
150
DevFest Android in Korea 2025 - 개발자 커뮤니티를 통해 얻는 가치
wisemuji
0
130
新卒エンジニアのプルリクエスト with AI駆動
fukunaga2025
0
210
これだけで丸わかり!LangChain v1.0 アップデートまとめ
os1ma
6
1.8k
非同期処理の迷宮を抜ける: 初学者がつまづく構造的な原因
pd1xx
1
710
AIコーディングエージェント(Gemini)
kondai24
0
210
How Software Deployment tools have changed in the past 20 years
geshan
0
29k
Microservices Platforms: When Team Topologies Meets Microservices Patterns
cer
PRO
1
1k
ハイパーメディア駆動アプリケーションとIslandアーキテクチャ: htmxによるWebアプリケーション開発と動的UIの局所的適用
nowaki28
0
420
251126 TestState APIってなんだっけ?Step Functionsテストどう変わる?
east_takumi
0
310
Featured
See All Featured
Optimising Largest Contentful Paint
csswizardry
37
3.5k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
285
14k
Imperfection Machines: The Place of Print at Facebook
scottboms
269
13k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.5k
Producing Creativity
orderedlist
PRO
348
40k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
VelocityConf: Rendering Performance Case Studies
addyosmani
333
24k
Six Lessons from altMBA
skipperchong
29
4.1k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.1k
Large-scale JavaScript Application Architecture
addyosmani
515
110k
[RailsConf 2023] Rails as a piece of cake
palkan
58
6.2k
Done Done
chrislema
186
16k
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