A summation problem

0

0 votes
Linear Algebra, fft, Fast Fourier transform, Hard, Mathematics
Problem

You are given an array A of integers of size N , and one more integer K. Now, we define K distinct functions, fi(l,r),1iK. All functions have the domain equal to the set of all ordered pairs of integers {(x,y):xy and 1x,yN}

fi(l,r)=(rj=la[j])i.

Now you need to find and print for for each of the K functions, the sum of function values of all elements in its domain. As the answer could be rather large, you need to find and print it Modulo 998244353, a widely used prime.

Input Format :

The first line contains 2 space separated integers N and K. The next line contains N space separated integers, denoting the given array.

Output Format:

Print K space separated integers, where the ith integer is the answer for the ith function described above.

Constraints :

1NK2106

1N,K106, this ensures the input/output size remains resonable.

0A[i]<998244353

Time Limit: 2.5
Memory Limit: 1024
Source Limit:
Explanation

Here, f1(1,1)=1,f1(1,2)=3,f1(1,3)=6,f1(2,2)=2,f1(2,3)=5,f1(3,3)=3, so answer = 1+3+6+2+5+3=20

Similarily,

f2(1,1)=1,f2(1,2)=9,f2(1,3)=36,f2(2,2)=4,f2(2,3)=25,f2(3,3)=9, so answer = 1+9+36+4+25+9=84

Editor Image

?