Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 : 1N10

10 points : 1N500

10 points : 1N5000

70 points : 1N300000

Sample Input:

10 0 1 2 3 4 5 6 7 8 9 

Sample Output:

160 

time-4 sec

mem-50000 bytes

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions