GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Thursday 16 June 2022

[Solution] Decinc Dividing Codeforces Solution | Codeforces Problem Solution 2022

F. Decinc Dividing
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Let's call an array a of m integers a1,a2,,am Decinc if a can be made increasing by removing a decreasing subsequence (possibly empty) from it.

  • For example, if a=[3,2,4,1,5], we can remove the decreasing subsequence [a1,a4] from a and obtain a=[2,4,5], which is increasing.

You are given a permutation p of numbers from 1 to n. Find the number of pairs of integers (l,r) with 1lrn such that p[lr] (the subarray of p from l to r) is a Decinc array.

Input

The first line contains a single integer n (1n2105)  — the size of p.

Solution Click Below:-  CLICK HERE

The second line contains n integers p1,p2,,pn (1pin, all pi are distinct)  — elements of the permutation.


Output

Output the number of pairs of integers (l,r) such that p[lr] (the subarray of p from l to r) is a Decinc array. 

No comments:

Post a Comment