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
snuke
January 20, 2013
Programming
0
330
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
550
Other Decks in Programming
See All in Programming
ノーコードからの脱出 -地獄のデスロード- / Escape from Base44
keisuke69
0
650
「10分以内に機能を消せる状態」 の実現のためにやっていること
togishima
1
250
AI時代に必須!状況言語化スキル / ai-context-verbalization
minodriven
3
360
Vue 3.6 時代のリアクティビティ最前線 〜Vapor/alien-signals の実践とパフォーマンス最適化〜
hiranuma
2
410
What's New in Web AI?
christianliebel
PRO
0
120
Making Angular Apps Smarter with Generative AI: Local and Offline-capable
christianliebel
PRO
0
110
pnpm に provenance のダウングレード を検出する PR を出してみた
ryo_manba
1
220
業務でAIを使いたい話
hnw
0
250
KoogではじめるAIエージェント開発
hiroaki404
1
400
マイベストのシンプルなデータ基盤の話 - Googleスイートとのつき合い方 / mybest-simple-data-architecture-google-nized
snhryt
0
130
釣り地図SNSにおける有料機能の実装
nokonoko1203
0
210
React Nativeならぬ"Vue Native"が実現するかも?_新世代マルチプラットフォーム開発フレームワークのLynxとLynxのVue.js対応を追ってみよう_Vue Lynx
yut0naga1_fa
2
2.1k
Featured
See All Featured
A Modern Web Designer's Workflow
chriscoyier
697
190k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
Speed Design
sergeychernyshev
32
1.2k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
34
2.3k
Mobile First: as difficult as doing things right
swwweet
225
10k
The Power of CSS Pseudo Elements
geoffreycrofte
80
6k
4 Signs Your Business is Dying
shpigford
186
22k
Agile that works and the tools we love
rasmusluckow
331
21k
Building Flexible Design Systems
yeseniaperezcruz
329
39k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.6k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
46
7.8k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
359
30k
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)ͷΞΠίϯ