From 2068a71c79cf52e9448ba2f94be978e789eaedff Mon Sep 17 00:00:00 2001 From: Benjamin Qi Date: Thu, 2 Jul 2020 15:03:09 -0400 Subject: [PATCH] upd slope a bit --- content/6_Plat/Slope.mdx | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/content/6_Plat/Slope.mdx b/content/6_Plat/Slope.mdx index 94c750a..6d1a3eb 100644 --- a/content/6_Plat/Slope.mdx +++ b/content/6_Plat/Slope.mdx @@ -12,20 +12,24 @@ import { Problem } from "../models"; export const metadata = { problems: { + ex: [ + new Problem("CF", "Problem Without a Legend", "contest/713/problem/C", "Easy", false, ["Slope Trick"], ""), + ], buy: [ - new Problem("CF", "Buy Low Sell High", "contest/866/problem/D", "Normal", false, ["Slope Trick"], ""), + new Problem("CF", "Buy Low Sell High", "contest/866/problem/D", "Easy", false, ["Slope Trick"], ""), ], potatoes: [ - new Problem("ojuz", "LMIO - Potatoes & Fertilizers", "LMIO19_bulves", "Hard", false, ["Slope Trick"], "[Equivalent Problem](https://atcoder.jp/contests/kupc2016/tasks/kupc2016_h)"), + new Problem("ojuz", "LMIO - Potatoes & Fertilizers", "LMIO19_bulves", "Normal", false, ["Slope Trick"], "[Equivalent Problem](https://atcoder.jp/contests/kupc2016/tasks/kupc2016_h)"), ], landscaping: [ - new Problem("Plat", "Landscaping", "650", "Very Hard", false, ["Slope Trick"], "Equivalent Problem: GP of Wroclaw 20 J"), + new Problem("Plat", "Landscaping", "650", "Hard", false, ["Slope Trick"], "Equivalent Problem: GP of Wroclaw 20 J"), ], general: [ new Problem("CF", "Bookface", "gym/102576/problem/C", "Normal", false, ["Slope Trick"], ""), new Problem("CC", "CCDSAP Exam", "CCDSAP", "Normal", false, ["Slope Trick"], ""), new Problem("CF", "Farm of Monsters", "gym/102538/problem/F", "Hard", false, ["Slope Trick"], ""), new Problem("CF", "Moving Walkways", "contest/1209/problem/H", "Hard", false, ["Slope Trick"], ""), + new Problem("ojuz", "APIO - Fireworks", "APIO16_fireworks", "Hard", false, [], ""), new Problem("CF", "April Fools' Problem", "contest/802/problem/O", "Very Hard", false, ["Slope Trick"], "binary search on top of slope trick"), new Problem("ICPC World Finals", "Conquer the World", "https://icpc.kattis.com/problems/conquertheworld", "Very Hard", false, ["Slope Trick"], "ICPC world finals, 0 solves in contest - \"Potatoes\" on tree!!"), ], @@ -35,8 +39,8 @@ export const metadata = { ## Tutorials - - + 3 problems using this trick + clarifying the above and another example problem From the latter link (modified): @@ -46,7 +50,7 @@ From the latter link (modified): > - It can be divided into multiple sections, where each section is a linear function (usually) with an integer slope. > - It is a convex/concave function. In other words, the slope of each section is non-decreasing or non-increasing when scanning the function from left to right. -It's generally applicable as a DP optimization. The rest of this module assumes that you are somewhat familiar with at least one of the tutorials mentioned above. +It's generally applicable as a DP optimization. @@ -54,6 +58,12 @@ Usually you can come up with a slower (usually $O(N^2)$) DP first and then optim +The rest of this module assumes that you know the basic idea of this trick. In particular, you should be at least somewhat familiar with the $O(N\log N)$ time solution to the first problem in zscoder's tutorial: + + + +It's ok if you found the explanations confusing; the example below should help clarify. + ## Buy Low Sell High @@ -158,7 +168,7 @@ dp[5] = { 3, -2, -9, -16, -25, -35} dif[5] = { 5, 7, 7, 9, 10} ``` -Again, we can choose to sell one share at price $9$. The last three DP values remain the same while the others change. +Again, we can choose to sell one share at price $9$. The last three DP values remain the same while the others change. $dif$ is still in increasing order! ``` dp[5] = { 7, 0, -7, -16, -25, -35}