Shil and Wave seqeunce
Practice
4.5 (36 votes)
Approved
Bit manipulation
Data structures
Dynamic programming
Medium
Open
Ready
Problem
90% Success 1236 Attempts 50 Points 1s Time Limit 256MB Memory 1024 KB Max Code
Given a sequence A1 , A2 , A3 .. AN of length N . Find total number of wave subsequences having length greater than 1.
Wave subsequence of sequence A1 , A2 , A3 .. AN is defined as a set of integers i1 , i2 .. ik such that Ai1 < Ai2 > Ai3 < Ai4 .... or Ai1 > Ai2 < Ai3 > Ai4 .... and i1 < i2 < ...< ik.Two subsequences i1 , i2 .. ik and j1 , j2 .. jm are considered different if k != m or there exists some index l such that il ! = jl
INPUT:
First line of input consists of integer N denoting total length of sequence.Next line consists of N integers A1 , A2 , A3 .. AN .
OUTPUT:
Output total number of wave subsequences of given sequence . Since answer can be large, output it modulo 109+7
CONSTRAINTS:
1 ≤ N ≤ 105
1 ≤ Ai ≤ 105
Submissions
Please login to view your submissions
Similar Problems
Points:50
1 votes
Tags:
Advanced Data StructuresData StructuresFenwick treeLine Sweep TechniqueMediumSegment Treesoffline
Points:50
3 votes
Tags:
Advanced Data StructuresData StructuresFenwick treeMedium
Points:50
36 votes
Tags:
Bit ManipulationGraphsMediumReadySegment Trees
Editorial