Hi, I posted some comments on each of the following problem's tutorial blogs, but maybe those comments were not noticed ( As I understand maybe people normally not go to blogs of those problems which they already have solved ). So this is my attempt to get some help from you guys :) . I will posts my problems in comment section on this blog, so that I can get some help in reply section .
Thank you all. Have a nice day :)
The problems I am seeking help is
(This blog will be edited frequently )
372C - Watching Fireworks is Fun
EDIT : Please scroll through the page for latest comment.
I have read DEGwer's editorial and tried to understand his code. But I can't figure out the sliding window part :(
As far I understood:
if I am at State DP[ i ][ j ] I need to find out the maximum value between the interval from DP[ i-1 ][ j-x ] ... through .... DP[ i-1 ][ j ] .... to .... DP[ i-1 ][ j+x ]
Where x= available time(i.e t[ i ]- t[ i-1 ]) * D i.e DEGwer represents x as interval in his code
My Questions are:
dp[1 - p][dq[dq.size() - 1]] <= dp[1 - p][(int)j]
I don't get this part :/I think this article might explain everything http://people.cs.uct.ac.za/~ksmith/articles/sliding_window_minimum.html
Thank you GaryYe for your reply. I'v read that fine article when the tutorial was published. And I think I understand the mechanism of sliding window technique. However I am still facing some problem understanding the solution. I will be back shortly with my idea so far on this problem in a comment.
368C - Sereja and Algorithm
Given input:
zyxxxxxxyyz
query no 4 is:1 4
which implieszyxx
and answer for this query isYES
As far I understood:
zyxx
zyxx
which doesn't equal to either string "zyx", "xzy", "yxz"But I don't understand:
If I take
yxx
(i.e: last three characters) and permute it randomly, and again take last 3 characters which is nothing but a combination of y , x , x . I can run this process infinite times. So should not my ans will be NO .And I also can not understand Author Sereja's solution
Any suggestion will be a great hand :)
First question: Use this anagram "xzyx" then you will only find the good substrings.
The idea is to arrange a string in the form of xzyxzyxzy... After playing around with some test cases, you will notice that one can arrange such string, iff max{Cx, Cy, Cz} - min{Cx, Cy, Cz} ≤ 1, where Ci denotes the occurrences of character i. One can calculate Ci in some range [l, r] in O(1) by using prefix sum.
Thanks GaryYe for your explanation.. Specially The idea is to arrange a string in the form of xzyxzyxzy << This part helped me to understand clearly :)
372C - Watching Fireworks is Fun
This comment is bulky and I apologize for that :)
I have a some confusions and allow me to describe them in order,
So as far I understand, my window must contain the index in which DP array holds the maximum value. So, It's obvious that when I am at state DP[ i ][ j ] , Best answer comes from the range of DP[ i-1 ][ j-interval ] .......... DP[ i-1 ][ j+interval ] . So, when I make the window I have to iterate through
j-interval .... j+interval
this range. But Author is iterating through only from 1 to intervalfor (lint j = 1; j <= interval; j++)
If I illustrate my thinking through an example, let
So, DP[ i ][ 15 ] must contain the maximum value from DP[ i ][ 12 ] .... DP[ i ][ 18 ] . So as my dq. But Sereja is making the dq in range from 1 to 3
How he is insuring that maximum value stay in this index range? What if maximum value stays at index 17? Please help me to understand