Question
For an array B while it has more than one element, you can apply an operation on it - you choose any two elements x
For an array B while it has more than one element, you can apply an operation on it - you choose any two elements x,y
(they may be the same value, but they should have different indices), delete them, and add an element g(x,y)
instead.
Here g(x,y)denotes the highest set bit in xy, or 0 if they are equal. In other words, g(x,y)=max2k, such that
2k(xy) for xy and g(x,y)=0
if x=y For example, g(1,1)=0,g(1,2)=2,g(2,4)=4,g(13,17)=16
.
Given an array B
, we try to apply the operations repeatedly in such a way that when we are left with only one element at the end, that element is as small as possible. Let's denote this smallest possible value of the element at the end as f(B)
.
You are given an array A
with N
elements, you need to find the sum of f(A l ...r)
among all subsegments 1lrN
The answer may be large, so you need to find it modulo 998244353
.
Input:
- The first line contains one integer N
.
The second line contains N
integers A1,A2,...,AN.
Output:
In a single line, print the sum, modulo 998244353
.
Constraints
- 1N300000
0Ai Subtasks 10 points : 1N500 10 points : 1N5000 70 points : 1N300000 Sample Input: Sample Output: time-4 sec mem-50000 bytes10 0 1 2 3 4 5 6 7 8 9
160
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started