Sub and super arrays

5

1 votes
Advanced Data Structures, Data Structures, Lazy Propagation in Interval/Segment Trees, Medium, Segment tree
Problem

You are given an array Arri of size N containing distinct integers. You have to choose two non-overlapping subarrays and join them to make a super array such that all elements in the super array are strictly in increasing order. Find the maximum size of the super array.

For example, if the given array is Arr[1,2.....i....j.....x...y....N] and you choose subarrays [i....j] and [x....y] to form the super array, then the super array will be [i....j,x...y] where (1ij<xyN).

Notes

  • The swapping of elements is not allowed.
  • The subarray in the final optimal answer will always contain distinct numbers.
  • It is always possible to choose 2 subarrays that follow the given criteria.

Input format

  • First line: T i.e number of test cases.
  • For each test case:
    • First line: N
    • Second line: N space-separated integers denoting elements of the array

Output format
Find the maximum size of the super array. Print the answer to each test case in a separate line.

Constraints
1T20
1N,Arri100000

 

Time Limit: 1.5
Memory Limit: 256
Source Limit:
Explanation

For the given array if we choose a sub array from index [2...5] and index [8...10] to make the super array, then we get the maximum size i.e 7.

Editor Image

?