Modified LIS
Practice
4.2 (36 votes)
Approved
Dynamic programming
Medium
Open
Ready
Segment trees
Trees
Problem
84% Success 1194 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given a sequence of N integers as A1, A2, ... , AN. Let B be a sub-sequences of A, of maximum possible length (say k), such that each of them satisfies following conditions:

  • |Bi| > |Bi-1|

  • Bi * Bi-1 < 0

for all i = 2, 3, ... k

Find number of distinct sub-sequences of length k that satisfy above conditions. Two sub-sequences are distinct if they are made up using different set of indices of sequence A.

CONSTRAINTS

1 ≤ N ≤ 105
-105 ≤ Ai ≤ 105 for all i = 1, 2, 3, ... N
Ai != 0 for all i = 1, 2, 3, ... N

INPUT

First line contains one integer N, denoting the size of input array. Next line contains N space separated integers, denoting the array A.

OUTPUT

Print two space separated integers, first one k, denoting the maximum possible size of such a sub-sequence and second integer d, the number of all such sub-sequences. Since d can be large, print it modulo 109+7.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
114 votes
Tags:
ApprovedData StructuresDynamic ProgrammingFenwick TreeHiringMediumReadySegment Trees
Points:30
103 votes
Tags:
MediumSegment TreesTrees
Points:30
23 votes
Tags:
AlgorithmsApprovedMediumOpenTreesTwo pointer