My Code link:https://codeforces.net/contest/1678/submission/156355337
My Logic: Store all Pairs [Ai,Aj] where Ai>Aj in a 2D Vector and similarly do for Ai<Aj. Now Make 4 length arrays using these two arrays as they have required PaPd pairs. If they meet the given condition check if position of elements of subsequence in original array is sorted or not using map, if sorted increment the answer.
Problem: It TLE's.
Thinking: I tired to think of optimization but unable to come up with. So can anyone help?