(xq,yq). We should signify the Manhattan distance between them as d(p,q)=|xp−xq|+|yp−yq|. Suppose that three focuses p, q, r structure an awful triple if d(p,r)=d(p,q)+d(q,r). Suppose that an
C++ only. Do not copy. Correct code will upvoted else downvote. Skip if you don't know.
Assume you have two focuses p=(xp,yp) and q=(xq,yq). We should signify the Manhattan distance between them as d(p,q)=|xp−xq|+|yp−yq|. Suppose that three focuses p, q, r structure an awful triple if d(p,r)=d(p,q)+d(q,r). Suppose that an exhibit b1,b2,… ,bm is acceptable in case it is difficult to pick three particular records I, j, k with the end goal that the focuses (bi,i), (bj,j) and (bk,k) structure an awful triple. You are given a cluster a1,a2,… ,an. Workout the number of good subarrays of a. A subarray of the cluster an is the exhibit al,al+1,… ,ar for some 1≤l≤r≤n.
Note that, as indicated by the definition, subarrays of length 1 and 2 are acceptable.
Input The primary line contains one integer t (1≤t≤5000) — the number of experiments.
The main line of each experiment contains one integer n (1≤n≤2⋅105) — the length of cluster a.
The second line of each experiment contains n integers a1,a2,… ,an (1≤
Output :For each experiment, print the number of good subarrays of exhibit a.
Step by step
Solved in 3 steps with 1 images