As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them:

Yuta has n numbers A[1]~A[n] and a number K. For any none empty subset S of the numbers, the value of S is equal to the sum of the largest min(|S|,k) numbers in S. The value of the array A is equal to the sum of the value of all none empty subset of the numbers.

Now Yuta shows the n numbers, And he wants to know the value of the array for each K in [1,n].

It is too difficult for Rikka. Can you help her?

InputThe first line contains a number t(1<=t<=10), the number of the testcases.

For each testcase, the first line contains a number n(1<=n<=100000), the number of numbers Yuta has. The second line contains n number A[1]~A[n](0<=A[i]<=10^9).OutputFor each testcase, print a line contains exactly n numbers, the ith number is the value of the array when K=i. The answer may be very large, so you only need to print the answer module 998244353.

Sample Input

2
3
1 1 1
5
1 2 3 4 5

Sample Output

7 11 12
129 201 231 239 240

题意:给定一个数组,F(k)表示所有集合s的前min(K,s)大之和。求所有F(k)。

思路:先得到方程f(x),然后一般来说一个组合数*一个指数,可以直接转化一下用NTT加速;或者用第二类斯特林转化,再套NTT或FFT卷积。

关键在于找到某两个系数之和为定值,然后分别以其为“基”构造函数,然后取卷积这两个函数。

#include<bits/stdc++.h>
#define rep(i,x,y) for(int i=x;i<=y;i++)
using namespace std;
#define ll long long
#define MOD Mod
const int G=;
const int maxn=;
const int Mod=;
int qpow(int v,int p)
{
int ans=;
for(;p;p>>=,v=1ll*v*v%Mod)
if(p&)ans=1ll*ans*v%Mod;
return ans;
}
void rader(int y[], int len) {
for(int i=,j=len/;i<len-;i++) {
if(i<j) swap(y[i],y[j]);
int k=len/;
while(j>=k) j-=k,k/=;
if(j<k) j+=k;
}
}
void NTT(int y[],int len,int opt) {
rader(y,len);
for(int h=;h<=len;h<<=) {
int wn=qpow(G,(MOD-)/h);
if(opt==-) wn=qpow(wn,Mod-);
for(int j=;j<len;j+=h) {
int w=;
for(int k=j;k<j+h/;k++) {
int u=y[k];
int t=(ll)w*y[k+h/]%MOD;
y[k]=(u+t)%MOD;
y[k+h/]=(u-t+MOD)%MOD;
w=(ll)w*wn%MOD;
}
}
}
if(opt==-) {
int t=qpow(len,MOD-);
for(int i=;i<len;i++) y[i]=(ll)y[i]*t%MOD;
}
}
int inv[maxn],A[maxn],B[maxn],a[maxn],f[maxn],p2[maxn];
int main() {
int T,N;
f[]=inv[]=p2[]=;
rep(i,,) p2[i]=(ll)p2[i-]*%Mod;
rep(i,,) f[i]=(ll)f[i-]*i%Mod;
inv[]=qpow(f[],Mod-);
for(int i=-;i>=;i--) inv[i]=(ll)inv[i+]*(i+)%Mod;
scanf("%d",&T);
while(T--){
scanf("%d",&N);
int len=; while(len<=N*) len<<=;
rep(i,,len) A[i]=B[i]=;
rep(i,,N) scanf("%d",&a[i]);
sort(a+,a+N+); reverse(a+,a+N+);
rep(i,,N-){
A[i]=inv[i];
B[i]=(ll)f[N-i-]*p2[i]%Mod*a[N-i]%Mod;
} NTT(A,len,); NTT(B,len,);
rep(i,,len-) A[i]=(ll)A[i]*B[i]%Mod; //乘完,不能只乘到N
NTT(A,len,-); int ans=;
rep(i,,N){
(ans+=(ll)inv[i-]*A[N-i]%Mod)%=Mod;
printf("%d ",ans);
}
puts("");
}
return ;
}

HDU - 5829:Rikka with Subset (NTT)的更多相关文章

  1. HDU 5829 Rikka with Subset(NTT)

    题意 给定 \(n\) 个数 \(a_1,a_2,\cdots a_n\),对于每个 \(K\in[1,n]\) ,求出 \(n\) 个数的每个子集的前 \(K\) 大数的和,输出每个值,对 \(99 ...

  2. HDU 6092 Rikka with Subset(dp)

    http://acm.hdu.edu.cn/showproblem.php?pid=6092 题意: 给出两个数组A和B,A数组一共可以有(1<<n)种不同的集合组合,B中则记录了每个数出 ...

  3. HDU - 6416 :Rikka with Seam(DP & 前缀和 & 数学)

    pro:给定N*M的矩阵,现在让你在每一行删去一个位置,然后形成新N*(M-1)的矩阵,问有多少种不同的新的矩阵.需要满足相邻行删去的位置不大于K. (题目是01矩阵,其实任意矩阵都可以做,本题算法里 ...

  4. HDU 5795:A Simple Nim(博弈)

    http://acm.hdu.edu.cn/showproblem.php?pid=5795 A Simple Nim Problem Description   Two players take t ...

  5. HDU 6188:Duizi and Shunzi(贪心)(广西邀请赛)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6188 题意 有n个数字,每个数字小于等于n,两个相同的数字价值为1,三个连续的数字价值为1 .问这n个 ...

  6. HDU 3183:A Magic Lamp(RMQ)

    http://acm.hdu.edu.cn/showproblem.php?pid=3183 题意:给出一个数,可以删除掉其中m个字符,要使得最后的数字最小,输出最后的数字(忽略前导零). 思路:设数 ...

  7. HDU 6011:Lotus and Characters(贪心)

    http://acm.hdu.edu.cn/showproblem.php?pid=6011 题意:共有n种字符,每种字符有一个val和一个cnt,代表这个字符的价值和数量.可以制造的总价值是:第一个 ...

  8. HDU 3487:Play with Chain(Splay)

    http://acm.hdu.edu.cn/showproblem.php?pid=3487 题意:有两种操作:1.Flip l r ,把 l 到 r 这段区间 reverse.2.Cut a b c ...

  9. HDU 5968:异或密码(暴力)

    http://acm.hdu.edu.cn/showproblem.php?pid=5968 题意:中文题意. 思路:一开始不会做,后来发现数据范围很小,而且那个数要是连续的,所以可能把所有情况枚举出 ...

随机推荐

  1. hadoop11----socket

    package cn.itcast.bigdata.socket; import java.io.BufferedReader; import java.io.InputStream; import ...

  2. 20165101刘天野 2018-2019-2《网络对抗技术》第1周 Kali的安装

    20165101刘天野 2018-2019-2<网络对抗技术>第1周 Kali的安装 一.实验要求 Kali下载 安装 网络 共享 软件源 二.实验步骤 1.下载 从Kali官网中下载相应 ...

  3. Linux系统下使用pwgen生成密码的使用教程

    pwgen生成的密码易于记忆且相当安全.从技术上来说,容易记忆的密码不会比随机生成的密码更加安全.但是,在大多数情况下,pwgen生成的密码已经足够安全,除了网银密码等需要高安全等级的情况外.使用易于 ...

  4. GitLab 安装与入门

    GitLab介绍: GitLab是一个利用 Ruby on Rails 开发的开源应用程序,实现一个自托管的Git项目仓库,可通过Web界面进行访问公开的或者私人项目. GitLab拥有与Github ...

  5. [BZOJ1116]CLO[并查集]

    看了样例突然发现= =无向边不会增加入度. 然后发现是环套环. 一个环所有点入度都为2. 最后的图无视所有无向边的话大概是这样的(将就一下 然后就可以并查集维护一下联通性... 当x , y属于一个联 ...

  6. java类敏感词过滤类

    package com.fpx.pcs.prealert.process.service.impl; import java.util.HashMap;import java.util.HashSet ...

  7. Remove Duplicates from Sorted List ,除去链表中相邻的重复元素

    Remove Duplicates from Sorted List : Given a sorted linked list, delete all duplicates such that eac ...

  8. TCP异步IO_服务端_测试

    1.测试代码来自于 JDK7 AIO初体验 http://www.iteye.com/topic/1113611 1.1. package aio; import java.net.InetSocke ...

  9. React菜鸟食谱

    JSX 用小括号包裹代码防止分号自动插入的bug,用大括号包裹里面的表达式 切记你使用了大括号包裹的 JavaScript 表达式时就不要再到外面套引号了.JSX 会将引号当中的内容识别为字符串而不是 ...

  10. css tips —— 可见性对图片加载的影响

    如果是<img />标签,无论是display: none:还是visibility: hidden;都会加载图片: 但是如果是背景图片即background-image: url(xxx ...