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
CodeForces#162 Div1-E
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
snuke
January 20, 2013
Programming
0
350
CodeForces#162 Div1-E
CodeForces#162 Div1-E の解説
snuke
January 20, 2013
Tweet
Share
More Decks by snuke
See All by snuke
puzzleLT.pdf
snuke
0
730
JOI2015-2016 春合宿 day 2 Sandwich 解説
snuke
0
310
JOI2015-sp-day4-walls-anothersolution
snuke
0
250
JOI2014 春合宿 day 2 スタンプラリー 解説
snuke
0
220
NPCA合宿きょーぷろ講義
snuke
0
360
JOI 2013 春合宿 day4-1 messenger 解説
snuke
0
380
CodeForces162 Div1-E
snuke
3
16k
SRM 555 Div 1 easy, Div 2 medium
snuke
1
460
SRM 555 Div 1 hard
snuke
1
570
Other Decks in Programming
See All in Programming
SourceGeneratorのススメ
htkym
0
190
IFSによる形状設計/デモシーンの魅力 @ 慶應大学SFC
gam0022
1
300
CSC307 Lecture 08
javiergs
PRO
0
670
AI によるインシデント初動調査の自動化を行う AI インシデントコマンダーを作った話
azukiazusa1
1
710
humanlayerのブログから学ぶ、良いCLAUDE.mdの書き方
tsukamoto1783
0
190
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
540
AI Schema Enrichment for your Oracle AI Database
thatjeffsmith
0
260
CSC307 Lecture 09
javiergs
PRO
1
830
Amazon Bedrockを活用したRAGの品質管理パイプライン構築
tosuri13
4
270
コントリビューターによるDenoのすゝめ / Deno Recommendations by a Contributor
petamoriken
0
200
今から始めるClaude Code超入門
448jp
8
8.6k
AIによるイベントストーミング図からのコード生成 / AI-powered code generation from Event Storming diagrams
nrslib
2
1.9k
Featured
See All Featured
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
64
How to train your dragon (web standard)
notwaldorf
97
6.5k
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.3k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
9.9k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
100
Accessibility Awareness
sabderemane
0
51
What does AI have to do with Human Rights?
axbom
PRO
0
2k
4 Signs Your Business is Dying
shpigford
187
22k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
0
320
Code Review Best Practice
trishagee
74
20k
Crafting Experiences
bethany
1
48
Transcript
CodeForces #162 Div1-E RodeSideTrees writer: snuke
֓ཁ 東西の道にそって木を植えたり切ったりするクエリ を処理し、各クエリ後に西→東方向のLISを求める 木は各クエリ前に1m ずつ伸びる 植える木の高さは10m 以下 切り倒す木は西から10本目以内 木の本数 N
≦ 10^5, クエリ数 M ≦ 2*10^5
۪ͳղ๏ 毎回 LIS を求める。 O(M N log N)となり、さすがに間に合わない。
ఆղ まず、木の成長を無視するために、 t 個目のクエリの時に植えられる木の高さを h から h-t に変換しておきます。 んで、木の(場所,高さ)を x-y平面上にぷろっとしてみる。
ఆղ ߴ͞ ॴ こんな感じ? すると・・・
ఆղ 常に右上方向に辿る最長経路がLISになってる! この場合、LISは赤いやつになります。 LISの普通の条件「hi < hi+1 」と暗黙の条件「xi < xi+1 」からくる特性
ߴ͞ ॴ
ఆղ さて、この問題におけるクエリは 下から10番目以内に木を追加 左から10番目以内の木を削除 と言い換えられます。 ߴ͞ ॴ
ఆղ とりあえず、各木に Longest Decreasing Subsequence の長さを記録することにしてみます。 図の木のところに LDS の長さを書き込んでみる。 木iの右上の領域中の最大値
+ 1 が 木iのところに書き込まれるシステムらしい。 ߴ͞ ॴ 1 1 1 2 2 3 4
ఆղ 各クエリを爆速で処理する方法を考えてみよう。 ある木の LDS には右上の領域にある木のみが影響を及ぼし、 左 or 下 にある木は影響を及ぼさないことを利用しよう。 ߴ͞
ॴ 1 1 1 2 2 3 4
ఆղ 植えるクエリ (下から10番目以内に木を追加) 植える木よりも低い木をいったん抜いて、 順番に植え直す。 ߴ͞ ॴ 1 1 1
2 2 3 4
ఆղ 切るクエリ (左から10番目以内の木を削除) 切る木よりも左の木をいったん抜いて、 切る木以外を順番に植え直す。 ߴ͞ ॴ 1 1 1
2 2 3 4
ఆղ さて、ここで必要になるデータ構造はなんでしょう? 2次元segtree? → 更新にO(log^2 N)かかり、しかも定数項重そうな ので多分TLEします。 ߴ͞ ॴ
1 1 1 2 2 3 4
ఆղ 植えるクエリの時には x 方向の1次元segtree 切るクエリの時には y 方向の1次元segtree だけしか必要ない! O(log N)しかも定数項軽め!
※ただし、ノードの更新は両方のsegtreeに適応しないといけません。 ߴ͞(y) ॴ (x) 1 1 1 2 2 3 4
O(N * 10 * log N) くらい ܭࢉྔ
作問するにあたってLISとちょっと 仲良くなれた気がする。 ご清聴(?)ありがとうございました! CF#162へのご参加ありがとうございました! ·ͱΊ ←twitter(@the_nikaidoes)ͷΞΠίϯ