Last active
July 15, 2020 13:33
-
-
Save specdrake/84a89d680c2866d1bf731a70d2a711e2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- For [p_1,p_2 ... p_n] | |
-- Find three indices i, j and k such that: | |
-- 1 ≤ i < j < k ≤ n; | |
-- p_i < p_j and p_j > p_k. | |
-- Or say that there are no such indices. | |
func :: S.Seq Int -> String | |
func sq = let (a,b,c,suc) = S.foldrWithIndex (\ind a (i, j, k, b) -> | |
case b of | |
0 -> | |
case compare a (S.index sq i) of | |
GT -> (ind, 0, 0, b+1) | |
EQ -> (ind, 0, 0, b+1) | |
LT -> (ind, 0, 0, b) | |
1 -> | |
case compare a (S.index sq i) of | |
GT -> (i, ind, k, b+1) | |
EQ -> (i, ind, k, b+1) | |
LT -> (ind, j, k, b) | |
2 -> | |
case compare a (S.index sq j) of | |
GT -> (j, ind, k, b) | |
EQ -> (j, ind, k, b) | |
LT -> (i, j, ind, b+1) | |
3 -> (i, j, k, 3) | |
) (0,0,0,0) sq | |
in case suc of | |
3 -> "YES\n" ++ show (c+1) ++ " " ++ show (b+1) ++ " " ++ show (a+1) | |
_ -> "NO\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment