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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
betrue12
November 13, 2018
Programming
0
2.4k
Educational Codeforces Round 54 E. Vasya and a Tree
ブログ解説用
betrue12
November 13, 2018
Tweet
Share
Other Decks in Programming
See All in Programming
見せてもらおうか、 OpenSearchの性能とやらを!
shunta27
1
130
Rで始めるML・LLM活用入門
wakamatsu_takumu
0
200
Nuxt Server Components
wattanx
0
120
Geminiをパートナーに神社DXシステムを個人開発した話(いなめぐDX 開発振り返り)
fujiba
0
100
Nostalgia Meets Technology: Super Mario with TypeScript
manfredsteyer
PRO
0
110
AI Assistants for Your Angular Solutions
manfredsteyer
PRO
0
160
「接続」—パフォーマンスチューニングの最後の一手 〜点と点を結ぶ、その一瞬のために〜
kentaroutakeda
3
1.9k
Takumiから考えるSecurity_Maturity_Model.pdf
gessy0129
1
160
守る「だけ」の優しいEMを抜けて、 事業とチームを両方見る視点を身につけた話
maroon8021
3
1.3k
Claude Code Skill入門
mayahoney
0
430
AI 開発合宿を通して得た学び
niftycorp
PRO
0
170
Reactive ❤️ Loom: A Forbidden Love Story
franz1981
2
160
Featured
See All Featured
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
VelocityConf: Rendering Performance Case Studies
addyosmani
333
24k
Discover your Explorer Soul
emna__ayadi
2
1.1k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
220
Optimizing for Happiness
mojombo
378
71k
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
91
The Illustrated Children's Guide to Kubernetes
chrisshort
51
52k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
690
The SEO Collaboration Effect
kristinabergwall1
0
400
Side Projects
sachag
455
43k
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