WHY MY CONVEX HULL WORKS!!!

Правка en1, от javacoder1, 2016-12-17 23:05:51

I was trying to solve this question of dynamic programming using the convex hull trick .

http://codeforces.net/contest/319/problem/C .

Here is a link to my implementation which got accepted.

http://codeforces.net/contest/319/submission/23071655.

But this submission is raising more concerns .In the query part of the struct i made for cht , i know i am supplying lines whose slope are continuously decreasing with x.So the query part is a kind of pointer algorithm which evaluates the intersection between the last two lines in the hull and moves forward if it finds it adequate because the points in which i am eveluating the lines are strictly incresing.But the problem is that i am popping lines in the insert part so suppose we have 4 lines in the hull and the cur pointer is at the last line.The next inserted line comes and pops everything but the last one so what cur was previously pointing does not exist , so this code should have given RTE , but why not ? I hope some experienced person might look through this code explaining why this didn't happen as well as whether my code is fully correct because i tried to make this one for the case too where the slopes are equal which is not demanded in this question.

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский javacoder1 2016-12-17 23:05:51 1266 Initial revision (published)