$30 off During Our Annual Pro Sale. View Details »
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
CodeForces#162 Div1-E
Search
snuke
January 20, 2013
Programming
0
340
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
710
JOI2015-2016 春合宿 day 2 Sandwich 解説
snuke
0
310
JOI2015-sp-day4-walls-anothersolution
snuke
0
240
JOI2014 春合宿 day 2 スタンプラリー 解説
snuke
0
210
NPCA合宿きょーぷろ講義
snuke
0
360
JOI 2013 春合宿 day4-1 messenger 解説
snuke
0
370
CodeForces162 Div1-E
snuke
3
16k
SRM 555 Div 1 easy, Div 2 medium
snuke
1
460
SRM 555 Div 1 hard
snuke
1
560
Other Decks in Programming
See All in Programming
How Software Deployment tools have changed in the past 20 years
geshan
0
29k
WebRTC、 綺麗に見るか滑らかに見るか
sublimer
1
160
S3 VectorsとStrands Agentsを利用したAgentic RAGシステムの構築
tosuri13
6
300
認証・認可の基本を学ぼう前編
kouyuume
0
190
sbt 2
xuwei_k
0
260
大体よく分かるscala.collection.immutable.HashMap ~ Compressed Hash-Array Mapped Prefix-tree (CHAMP) ~
matsu_chara
1
220
SwiftUIで本格音ゲー実装してみた
hypebeans
0
110
dotfiles 式年遷宮 令和最新版
masawada
1
750
手軽に積ん読を増やすには?/読みたい本と付き合うには?
o0h
PRO
1
170
ソフトウェア設計の課題・原則・実践技法
masuda220
PRO
26
22k
手が足りない!兼業データエンジニアに必要だったアーキテクチャと立ち回り
zinkosuke
0
600
AIエンジニアリングのご紹介 / Introduction to AI Engineering
rkaga
5
2k
Featured
See All Featured
Faster Mobile Websites
deanohume
310
31k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
10
720
BBQ
matthewcrist
89
9.9k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.6k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
48
9.8k
Speed Design
sergeychernyshev
33
1.4k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.1k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
36
6.2k
Leading Effective Engineering Teams in the AI Era
addyosmani
8
1.3k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
37
2.6k
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)ͷΞΠίϯ