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
CodeForces#162 Div1-E
Search
snuke
January 20, 2013
Programming
370
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
CodeForces#162 Div1-E
CodeForces#162 Div1-E の解説
snuke
January 20, 2013
More Decks by snuke
See All by snuke
puzzleLT.pdf
snuke
0
750
JOI2015-2016 春合宿 day 2 Sandwich 解説
snuke
0
330
JOI2015-sp-day4-walls-anothersolution
snuke
0
260
JOI2014 春合宿 day 2 スタンプラリー 解説
snuke
0
230
NPCA合宿きょーぷろ講義
snuke
0
380
JOI 2013 春合宿 day4-1 messenger 解説
snuke
0
390
CodeForces162 Div1-E
snuke
3
16k
SRM 555 Div 1 easy, Div 2 medium
snuke
1
490
SRM 555 Div 1 hard
snuke
1
600
Other Decks in Programming
See All in Programming
Domain-Driven Transformation
hschwentner
2
2.3k
技術的負債の返済は、AI時代の複利で効く投資 — 経営としての意思決定とその遂行
curekoshimizu
1
2.3k
KiroのSpecで「五目並べ」を作ってみる
satoshi256kbyte
1
370
なぜCTOを降りてFDEを選んだのか?〜なぜプロダクト企業がFDEで顧客の現場に踏み込むのか〜
gonta
1
180
ハーネス設計入門 〜 基礎知識の整理から実務へのステップアップ 〜
kinopeee
22
22k
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
530
Rでドレミ/Do-Re-Mi_with_R
florets1
0
130
個人開発者よ、Honoを使え(おじさんver)
tanahiro2010
2
210
re:Inventに行く前に知っておきたい現地参加のノウハウ
nokomoro3
0
400
Turning Architecture into Unit Tests in the AI Era (NSSpain XIV)
steliosf
PRO
1
140
AI時代のコードレビューは人に向けるな、仕組みに向けろ
texmeijin
5
3.6k
sbt 2.0: takeoff
eed3si9n
0
110
Featured
See All Featured
The untapped power of vector embeddings
frankvandijk
2
1.9k
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
2
2k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.9k
The Curious Case for Waylosing
cassininazir
1
560
brightonSEO & MeasureFest 2025 - Winning Strategies for Black Friday CRO & PPC - Christian Goodrich
cargoodrich
3
860
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.5k
Product Roadmaps are Hard
iamctodd
55
13k
The Invisible Side of Design
smashingmag
301
52k
Speed Design
sergeychernyshev
33
2.1k
Facilitating Awesome Meetings
lara
57
7.2k
WENDY [Excerpt]
tessaabrams
14
40k
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)ͷΞΠίϯ