elizabeth_zou_fanboi's blog

By elizabeth_zou_fanboi, history, 10 months ago, In English

If the operation in this question (round 1063 B) is changed as follows: Choose any two integers l and r such that 1≤l≤r≤n. If, for ALL i in range (l,r) , min(pl,pr)<pi<max(pl,pr) holds true then set si to 1 for ALL i in range (l,r)

Is there solution to this variation. I spent whole contest on this variation (misread the question). I want to know whether solution exists in O(n) or not.

My O(n*5) solution that I am not sure is correct:

my code
»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by elizabeth_zou_fanboi (previous revision, new revision, compare).

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Maintain 4 stack call lmn,rmn,lmx,rmx. I’ll explain this one working with rmn and lmx and you can work the other case. After getting this stack, you can for each i, find the maximum r that the interval is valid by looking at the maximum r <= rmn[i] where lmx[r] <= i. Now you maintain this max pair {r,i} as you sweep the string and only use it when s[i] == 1 and it hasn’t been convered yet. With this approach you can find minimum intervals to cover the whole string

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by elizabeth_zou_fanboi (previous revision, new revision, compare).