Simple Sum
Practice
4.3 (7 votes)
Advanced data structures
Data structures
Medium
Range query
Segment trees
Problem
87% Success 1609 Attempts 50 Points 2s Time Limit 256MB Memory 1024 KB Max Code
You have been given an array of N integers \(A_1,A_2..A_N\). You have to find simple sum for this array. Simple Sum is defined as \(\sum_{i=1}^{i=N}\sum_{j=i}^{j=N}max(A_i, A_{i +1}, \dots, A_{j} ) * (A_i | A_j)\). | denotes the bitwise OR operator.
INPUT:
First line of input consists of integer N. Next line of input consists of N integers \(A_1,A_2..A_N\).
OUTPUT:
Print the simple sum of given array.
CONSTRAINTS:
1 ≤ N ≤ 105
1 ≤ \(A_i\) ≤ 104
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
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:50
10 votes
Tags:
ApprovedBinary SearchData StructuresMediumMerge sortOpenSegment Trees
Points:50
5 votes
Tags:
Advanced Data StructuresData StructuresMediumSegment Trees
Points:50
3 votes
Tags:
Advanced Data StructuresData StructuresMediumSegment Trees
Editorial
Login to unlock the editorial