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
Submissions
Please login to view your submissions
Similar Problems
Points:50
2 votes
Tags:
Data StructuresDepth First SearchGraphsMediumSegment Trees
Points:50
8 votes
Tags:
MediumSegment Trees
Points:50
2 votes
Tags:
Segment TreesData StructuresCombinatoricsImplementationAdvanced Data StructuresGraphsSegment treeBasics of Implementation
Editorial