Sherlock and Subarrays
Tag(s):

## Medium-Hard

Problem
Editorial
Analytics

Watson decided to test Sherlock's skills on his birthday by giving him the following problem-
Given an array of N elements, find how many subarrays have their Mystery value in $[L,R]$ inclusive. Mystery value for a subarray is defined as the AND(&) of all the values in the subarray.

Input Format
First line contains N, the number of elements.
Second line contains N space seperated integers.

Constraints

• $1 \le N \le 10^5$
• $1 \le A[i] \le 10^9$

Output Format
Output a single line containing the answer.

SAMPLE INPUT
5 2 4
1 2 3 4 5
SAMPLE OUTPUT
5
Time Limit: 5.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Swift-4.1, Visual Basic

## CODE EDITOR

Initializing Code Editor...

## This Problem was Asked in

Challenge Name

221B Baker Street: Code for Watson

OTHER PROBLEMS OF THIS CHALLENGE
• Data Structures > Advanced Data Structures
• Algorithms > String Algorithms
• Math > Game Theory
• Algorithms > Graphs
• Algorithms > Graphs