JZOJ 幽幽子与森林

计算机网络---万维网(WWW) WWW的概念与组成结构;WWW,万维网;超文本传输协议(HTTP); 阅读详情

题目大意:

迷途竹林可以看成是一个n个点的森林,幽幽子定义dis(u,v)为u到v路径上的边的数量,若u和v不连通则为m。她定义整个森林的危险度为
为了去拜访永琳师匠,幽幽子需要提前知道迷途竹林的危险度。但迷途竹林的形态是时刻变化着的,所以幽幽子希望知道危险度的期望是多少。
为了避免浮点运算,答案对998244353取模。
1<=n<=2e5

题解:

这个计数写得真的是累。

很容易想到设:
f[i]f[i]f[i]表示i个点生成树个数
g[i]g[i]g[i]表示i个点生成森林计数
c[i]c[i]c[i]表示i个点生成树的距离平方和。

只要能求出这三个东西,再随便卷卷就能搞出来答案了。

f[0]=f[1]=1,f[i]=ii−2(i&gt;1)f[0]=f[1]=1,f[i]=i^{i-2}(i&gt;1)f[0]=f[1]=1,f[i]=ii−2(i>1)
g=efg=e^fg=ef,一些阶乘忽略掉了

copy个版还算轻松。

然后就是求c。

思路为距离平方和拆为中间的有序点对数*2-点的个数+1。

那么考虑枚举这两个有序点对,大概是三个数组卷起来。

再枚举点,大概是两个数组卷起来。

然后就愉快的解决了这题。

Code:

#include<vector>
#include<cstdio>
#include<algorithm>
#define ll long long
#define pp printf
#define fo(i, x, y) for(int i = x, B = y; i <= B; i ++)
#define ff(i, x, y) for(int i = x, B = y; i <  B; i ++)
#define fd(i, x, y) for(int i = x, B = y; i >= B; i --)
#define pb push_back
using namespace std;

typedef vector<ll> V;

const int N = (1 << 21) + 5;

const int mo = 998244353;

ll ksm(ll x, ll y) {
    ll s = 1;
    for(; y; y /= 2, x = x * x % mo)
        if(y & 1) s = s * x % mo;
    return s;
}

int r[N]; ll aa[N];

void dft(V &b, int f) {
	int n = b.size();
    ff(i, 0, n) aa[i] = b[i];
    ff(i, 0, n) {
        r[i] = r[i / 2] / 2 + (i & 1) * (n / 2);
        if(i < r[i]) swap(aa[i], aa[r[i]]);
    }
    for(int h = 1; h < n; h *= 2) {
        ll wn = ksm(ksm(3, (mo - 1) / 2 / h), f == -1 ? mo - 2 : 1);
        for(int j = 0; j < n; j += 2 * h) {
            ll A, W = 1, *l = aa + j, *r = aa + j + h;
            ff(i, 0, h) {
                A = *r * W, *r = (*l - A) % mo, *l = (*l + A) % mo;
                W = W * wn % mo; l ++; r ++;
            }
        }
    }
    if(f == -1) {
        ll v = ksm(n, mo - 2);
        ff(i, 0, n) aa[i] = (aa[i] + mo) * v % mo;
    }
    ff(i, 0, n) b[i] = aa[i];
}

V operator * (V a, V b) {
    int z = a.size() + b.size() - 1;
    int n = 1; while(n < z) n *= 2;
    a.resize(n); b.resize(n);
    dft(a, 1); dft(b, 1);
    ff(i, 0, n) a[i] = a[i] * b[i] % mo;
    dft(a, -1); a.resize(z); return a;
}

V operator - (V a, V b) {
	if(a.size() < b.size()) a.resize(b.size());
	ff(i, 0, a.size()) a[i] = (a[i] - b[i] + mo) % mo;
	return a;
}

V qni(V a) {
    int n0 = 1; while(n0 < a.size()) n0 *= 2;
    V b; b.clear(); b.pb(ksm(a[0], mo - 2));
    for(int n = 2; n <= n0; n *= 2) {
        b.resize(n * 2); dft(b, 1);
        V c = a; c.resize(n); c.resize(n * 2); dft(c, 1);
        ff(i, 0, n * 2) b[i] = (b[i] * 2 - b[i] * b[i] % mo * c[i]) % mo;
        dft(b, -1); b.resize(n);
    }
    b.resize(a.size()); return b;
}

V qd(V a) {
    a[0] = 0;
    ff(i, 1, a.size()) a[i - 1] = a[i] * i % mo;
    return a;
}

V jf(V a) {
    a.pb(0);
    fd(i, a.size(), 1) a[i] = a[i - 1] * ksm(i, mo - 2) % mo;
    a[0] = 0;
    return a;
}

V ln(V a) {
    int sa = a.size();
    V b = a; b = qni(b); a = qd(a);
    a = a * b; a = jf(a); a.resize(sa);
    return a;
}

V exp(V a) {
    int n0 = 1; while(n0 < a.size()) n0 *= 2;
    V b; b.clear(); b.pb(1);
    for(int n = 2; n <= n0; n *= 2) {
		V c = b; c.resize(n); c = ln(c);
		V d = a; d.resize(n);
		c = c - d;
		c.resize(2 * n); dft(c, 1);
		b.resize(2 * n); dft(b, 1);
		ff(i, 0, 2 * n) b[i] = (b[i] - c[i] * b[i]) % mo;
		dft(b, -1); b.resize(n);
	}
	b.resize(a.size());
	return b;
}

int T, n, m;
ll fac[N], nf[N], f[N];
int n0;

V a, b;

ll c[N], d[N], ans1[N], ans2[N];

ll ni2;

int main() { 
	n = 2e5;
	fac[0] = 1; fo(i, 1, n) fac[i] = fac[i - 1] * i % mo;
	nf[n] = ksm(fac[n], mo - 2); fd(i, n, 1) nf[i - 1] = nf[i] * i % mo;
	f[0] = f[1] = 1; fo(i, 2, n) f[i] = ksm(i, i - 2);
	n0 = 1; while(n0 <= n) n0 *= 2;
	
	a.resize(4 * n0); b.resize(4 * n0);
	fo(i, 1, n) a[i] = b[i] = f[i] * i % mo * i % mo * nf[i] % mo;
	b[0] = 1;
	
	dft(a, 1); dft(b, 1);
	ff(i, 0, a.size()) a[i] = a[i] * a[i] % mo * b[i] % mo;
	dft(a, -1);
	
	fo(i, 1, n) c[i] = a[i] * fac[i] * 2 % mo;
	a.clear(); a.resize(2 * n0);
	b.clear(); b.resize(2 * n0);
	fo(i, 1, n) a[i] = f[i] * i % mo * i % mo * nf[i] % mo;
	dft(a, 1);
	ff(i, 0, a.size()) a[i] = a[i] * a[i] % mo;
	dft(a, -1);
	fo(i, 1, n) c[i] = (c[i] - a[i] * fac[i]) % mo;
	
	a.clear(); a.resize(n + 1);
	fo(i, 1, n) a[i] = f[i] * nf[i] % mo;
	a = exp(a);
	fo(i, 0, n) d[i] = a[i] * fac[i] % mo;
	
	a.clear(); a.resize(n + 1);
	fo(i, 1, n) a[i] = c[i] * nf[i] % mo;
	b.clear(); b.resize(n + 1);
	fo(i, 0, n) b[i] = d[i] * nf[i] % mo;
	a = a * b;
	fo(i, 1, n) ans1[i] = a[i] * fac[i] % mo;
	
	a.clear(); a.resize(n + 1);
	fo(i, 1, n) a[i] = f[i] * nf[i] % mo * i % mo;
	b.clear(); b.resize(n + 1);
	fo(i, 1, n) b[i] = d[i] * nf[i] % mo * i % mo;
	a = a * b;
	fo(i, 1, n) ans2[i] = a[i] * fac[i] % mo;
	
	ni2 = ksm(2, mo - 2);
	for(scanf("%d", &T); T; T --) {
		scanf("%d %d", &n, &m);
		pp("%lld\n", (ans1[n] + ans2[n] * m % mo * m) % mo * ksm(d[n], mo - 2) % mo * ni2 % mo);
	}
}
You have 18 unapplied migration(s). Your project may not work properly until you apply the migration django解决错误:You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.Run 'python manage.py migrate' to apply them. 阅读详情

相关推荐

Mysql远程数据库同步解决方案

服务器A中数据库youjihui_zs中的数据表t_index和服务器B中数据库youjihui_cx中数据表t_index_cx数据同步。

Metasploit - auxiliary/gather/zoomeye_search

How to use ZoomEye API ?If you are a python developer, please view ZoomEye-SDK. If not, ZoomEye API Documentation is good for you.$ sudo easy_install zoomeye-SDKor$ sudo pip install git+https://github.

Nixawk 59万+

CCC数字钥匙3.0标准解读(22)

介绍设备制造商服务器和车辆制造商服务器之间的通信协议.

weixin_41738640的博客 1759

使用官方提供的帮助也下载不了源码的解决方案

Downloading the Source Tree Installing Repo Repo is a tool that makes it easier to work with Git in the context of Android. For more information about Repo, see Version Control. To install, initia

android大牛MrJing 活动中心 2304

Frida精准定位Shopee x-sap-ri动态签名生成函数

x-sap-ri是Shopee客户端生成的上下文感知型动态令牌,本质为基于设备标识、请求路径与毫秒级时间戳三元组的SHA256哈希值,经Base64编码后作为防重放与防批量伪造的核心校验字段。其生成逻辑深度混淆且跨Java/Native层,静态分析失效,而Frida凭借内存级函数调用拦截与JNI层穿透能力,成为唯一可行的技术路径。本文聚焦Frida在加固App中的实战适配——通过libcrypto.so API特征扫描反向定位被抹名的生成函数,实现对x-sap-ri输入参数(如16字节device_id加密

weixin_33978578的博客 622

深入解析MATLAB四旋翼仿真案例asbQuadcopter的核心模块与优化技巧

本文深入解析了MATLAB/Simulink中的四旋翼无人机官方案例asbQuadcopter,详细拆解了其指令、传感器、控制器、本体与环境等核心模块的工作原理。重点探讨了经典的PID双环控制结构、传感器噪声模拟、模型替换方法以及系统化的PID参数调优技巧,旨在帮助用户从“开箱即用”过渡到深度定制与优化,构建更精准的仿真模型。

weixin_29171087的博客 369

download video from "ku6" web site and change to mp3

1. download 酷6网视频下载器2. use it to download video (video format is mp4, one video is separated to multiple mp4 files)3. use "Any Audio Converter" (http://www.any-audio-converter.com) to change mp4 t

Tomson Xu 6万+

手把手教你用U盘给海信IP501H刷机:GK6323V100C芯片的4.4.2和9.0固件实战

本文详细介绍了海信IP501H电视盒子基于GK6323V100C芯片的刷机实战指南,涵盖Android 4.4.2强刷和Android 9.0免拆刷机两种方案。从工具准备、短接操作到ADB调试,提供全流程解析和常见问题解决方案,帮助用户安全高效地完成刷机操作。

lemon的博客 1497

ZOJ - 2313 Chinese Girls' Amusement

You must have heard that the Chinese culture is quite different from that of Europe or Russia. So some Chinese habits seem quite unusual or even weird to us. So it is known that there is one popular

qqchanmingdexiaji的博客 4万+

模电实验室:手把手教你调试共射放大电路静态工作点(避免波形失真)

本文详细介绍了共射放大电路静态工作点的调试方法,帮助避免波形失真问题。从实验准备、电路搭建到静态工作点测量,提供了实用的电阻选值策略和常见波形失真解决方案,适合电子相关专业学生和硬件工程师参考学习。

weixin_42531128的博客 389

Sigrity Power DC Package Multi-Resistor Compact ET Model Extraction模式提取封装基板电热阻模型

DIE(定义DIE的参数):material设置为silicon(硅),Attach material(贴片的材料,设置为Die Attach),Attach thickness(贴片的材料的厚度,厚度设置为0.001mm,点击ok。Cap为覆盖材料,Material定义材料类型,thickness定义厚度,length和width定义长宽,Adhesive Material为胶的材料,Adhesive Material为胶的厚度,本例不定义,跳过即可。

weixin_54787054的博客 448

ミスチルのアルバム『I♥U』

Mr.Children『I♥U』 ~『深海』から9年。いざ、潜水。~  待ちに待ったMr.Childrenの最新アルバムが、ついに発売日を迎えた。前にも書いたことがあるが、最も好きなミュージシャン(バンド)を1人選べと言われたら、僕は迷わず”ミスチル”を選ぶ。ミスチルのアルバムをはじめて通して聴く瞬間。それは、僕にとって、最高に胸躍るひととき。だから、ニューアルバムをはじめて聴ける今日という日は、

azikanho的专栏 2万+

电子凸轮追剪算法深度解析:2500字图解+代码实战

工艺需求:在物料连续运动过程中完成精准切割核心矛盾:切割瞬间刀具与物料必须绝对同步传统方案:机械凸轮(结构复杂,调整困难)现代方案:电子凸轮(柔性可调,精度更高)

QQ_778132974的博客 1126

来破个处

rt~~~~~~~~~ 

xxyxxyxxyxxyxxyou的专栏 14万+

Qt for WebAssembly环境搭建

一、前言 二、Ubuntu 1、在线安装Qt15 在线安装下载器:https://download.qt.io/official_releases/online_installers/ 安装时记得勾选WebAssembly,如下: 2、安装依赖 # Install Python sudo apt-get install python2.7 # Install CMake (optional, only needed for tests and building Binaryen) sudo apt

贝勒里恩的博客 3678

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

http://www.grottoplumbing.com/cheapjerseys.php 7

?What matters is for you to own the brand in front of those you wish to convince the metatarsal bones from penet...

congji4807的博客 15万+

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

zoj 3735 Josephina and RPG (2013 亚洲区域赛 长沙站 J)

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3735  Josephina and RPG Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge A role-playing game (RPG and so

ddyyxx的程序员之路 1万+

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

nobody knows u r a dog

everything seems stupid.for the first time of a long time,the pressure strikes me.i saw lots of  people wanna join BUAA today .it freaks me more when i cant give the answers to the questions of las

什么是blog 5万+

zzz,zzz,zz9_ZZZ的完整形式是什么?

zzz,zzz,zz9 ZZZ:睡觉,无聊,累 (ZZZ: Sleeping, Bored, Tired) ZZZ is an abbreviation of "Sleeping, Bored, Tired". ZZZ是“睡觉,无聊,累了”的缩写 。 It is an expression, which is commonly used in messaging or chatting on ...

cumudi0723的博客 32万+

requires XXX>=YYY, but you‘ll have XXXX=ZZZ which is incompatible

这个报错是XXX包版本过低,升级即可 pip install -U XXX

GodGump的博客 18万+

【收藏】The top 200 sites on the web

The top 200 sites on the web【整理】 SkySeraph Apr 10th 2011  HQU Email:zgzhaobo@gmail.com    QQ:452728574 Latest Modified Date:Apr 10th 2011 HQU   1Googlegoogle.com Enables users to search the We...

weixin_34357267的博客 32万+

@

http://nshipster.com/at-compiler-directives/ @ Written by Mattt Thompson on Oct 8th, 2012 Birdwatchers refer to it as (and I swear I'm not making this up) "Jizz": those indefinable char

呆萌院长 1万+

Mothers as Seen Through the Eyes, and the Years, of TV and Film

Mothers as Seen Through the Eyes, and the Years, of TV and Film Some examples of how, as women in general have become more independent, so have the moms created by Hollywood. Transcript of radio bro

彪悍人生不需要去解释 9833

2019中国大学生程序设计竞赛-女生专场(重现赛)

题目链接 B:Gcd: 题意: 将1—n这n个数字分成两组,每组至少有一个数字,然后求两组的数的总和的最大公约数。 第一点,要想到分成两组,就是他们两组要够分 第二点,可以通过第一点联想到1–n的总和除以sum的最小因子(除1以外),然后这两组就够分了,所以sum / k 就是最大公约数。 #include <bits/stdc++.h> using namespace std; #define int long long signed main() { int n; ci

qq_45772236的博客 1万+

Android LoveYou

两个人在一起主要就是陪伴,俗话说得好:陪伴是最长情的告白. 马上521了.是五月二十一哦,在一起他的第二个生日了,做了一个app给他 你们想看的可以看哦,截几张图给大家分享一下 https://github.com/bggs/LoveYouApp.git 下载地址即可,不想下载的可以联系我要apk哦 ...

小婕儿的CSDN 1750

输入身高体重测身材_【测试】你的身材标准吗? 附赠20-39岁成年人身高体重评分标准...

该楼层疑似违规已被系统折叠隐藏此楼查看此楼你的身材标准吗?自我测试一下把http://www.youxigao.com/play.php?id=7212ps.20-29岁成年人身高标准体重评分表(男)身高段(厘米)体   重 (千 克)1分3分5分3分1分144.0-144.9<36.636.6-37.637.7-48.248.3-52.3>52.3145.0-1...

weixin_42548752的博客 1万+
上一篇: 【GDOI2019模拟2019.2.23】字符串
下一篇: 原根相关
Cold_Chair
博客等级 码龄11年 158粉丝 410原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值