All Tracks Data Structures Advanced Data Structures Segment Trees Problem

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++, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala 2.11.8, Swift, Visual Basic

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

This Problem was Asked in

School of Engineering, CUSAT

Challenge Name

221B Baker Street: Code for Watson

OTHER PROBLEMS OF THIS CHALLENGE
Notifications
View All Notifications