当前位置:网站首页>P5472 [NOI2019] 斗主地(期望、数学)
P5472 [NOI2019] 斗主地(期望、数学)
2022-07-28 11:12:00 【wind__whisper】
前言
我咋连表都没打啊。
too vegetable。
解析
题目给出的洗牌形式看着并不好看,合理猜测可以发现,这其实就等价于所有可能情况等概率出现。然后就不会了
打表可以发现:当 tp=1 时,dp 数组是一个等差数列。当 tp=2 时,dp 数组的差分是一个等差数列。
进一步猜测:如果原来的dp数组是 i 次多项式,那么洗牌后还是 i i i 次多项式。然而我并不会证
有了这个结论后,不断维护这个不超过二次的多项式的系数就做完了。
代码
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define ok debug("line: %d\n",__LINE__)
inline ll read(){
ll x(0),f(1);char c=getchar();
while(!isdigit(c)) {
if(c=='-')f=-1;c=getchar();}
while(isdigit(c)) {
x=(x<<1)+(x<<3)+c-'0';c=getchar();}
return x*f;
}
bool mem1;
const int N=1e7+100;
const int inf=1e9+100;
const int mod=998244353;
const bool Flag=0;
#define add(x,y) ((((x)+=(y))>=mod)&&((x)-=mod))
inline ll ksm(ll x,ll k){
ll res(1);
while(k){
if(k&1) res=res*x%mod;
x=x*x%mod;
k>>=1;
}
return res;
}
int n,m;
ll a,b,c;
inline ll calc(ll x){
return (x*x%mod*a+b*x+c)%mod;}
bool mem2;
signed main(){
#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif
debug("mem=%lf\n",abs(&mem2-&mem1)/1024./1024);
n=read();m=read();int tp=read();
//n=1e7;m=5e5;int tp=2;
a=tp==2;b=tp==1;c=0;
ll niv1=ksm((1ll*n*n-1-3*(n-1))%mod,mod-2);
ll nin=ksm(n,mod-2),nin1=ksm(n-1,mod-2);
for(int i=1;i<=m;i++){
int A=read();
//int A=rand()%n+1;
ll f1=calc(1),f2=calc(2),fa=calc(A),fa1=calc(A+1),fa2=calc(A+2),fn=calc(n);
ll x=(A*f1+(n-A)%mod*fa1)%mod*nin%mod;
ll y=(A*((A-1)*f2%mod+(n-A)*fa1%mod)+(n-A)*(A*f1%mod+(n-A-1)*fa2%mod))%mod*nin%mod*nin1%mod;
ll z=(A*fa+(n-A)*fn)%mod*nin%mod;
//printf("x=%lld y=%lld z=%lld\n",x,y,z);
a=(z-x-(n-1)*(y+mod-x)%mod+mod+mod)%mod*niv1%mod;
b=(y-x-3*a%mod+mod+mod)%mod;
c=(x-a-b+mod+mod)%mod;
}
int ask=read();
while(ask--){
printf("%lld\n",calc(read()));
}
return 0;
}
边栏推荐
- Ripro9.0 revised and upgraded version +wp two beautification packages + rare plug-ins
- 拥抱开源指南
- AlexNet—论文分析及复现
- 「以云为核,无感极速」第五代验证码重磅来袭
- I/O实操之对象流(序列化与反序列化)
- Tiktok programmer confession special code tutorial (how to play Tiktok)
- R language uses LM function to build regression model with interactive items, and uses: sign (colon) to represent the interaction of variables (colon is pure multiplication, excluding the constituent
- Advanced database technology learning notes 1 -- Oracle deployment and pl/sql overview
- Flutter tutorial flutter navigator 2.0 with gorouter, use go_ Router package learn about the declarative routing mechanism in fluent (tutorial includes source code)
- PHP检测url网址链接是否正常可访问
猜你喜欢

Learning notes tree array

Ten thousand words detailed Google play online application standard package format AAB

Service Workers让网站动态加载Webp图片

108. Introduction to the usage of SAP ui5 image display control Avatar

What is WordPress

LabVIEW AI视觉工具包(非NI Vision)下载与安装教程

Cvpr2021 pedestrian re identification /person re identification paper + summary of open source code
![[applet] how to notify users of wechat applet version update?](/img/04/848a3d2932e0dc73adb6683c4dca7a.png)
[applet] how to notify users of wechat applet version update?

对话庄表伟:开源第一课

ripro9.0修正升级版+WP两款美化包+稀有插件
随机推荐
【MySQL】Got an error reading communication packets
Localization, low latency, green and low carbon: Alibaba cloud officially launched Fuzhou data center
Server online speed measurement system source code
STM32 drives st7701s chip (V ⅰ V0 mobile phone screen change price)
R language ggplot2 visualization: use the ggdotplot function of ggpubr package to visualize the grouped dot plot, set the palette parameter, and set the color of data points in different grouped dot p
Database advanced learning notes cursor
[pyGame practice] when the end of the world comes, how long can you live in a cruel survival game that really starts from scratch?
[geek challenge 2019] babysql-1 | SQL injection
Understand how to prevent tampering and hijacking of device fingerprints
Advanced database technology learning notes 1 -- Oracle deployment and pl/sql overview
R language ggplot2 visualization: use the ggdotplot function of ggpubr package to visualize dot plot, set the add parameter, add violin graph to the dot plot, and add the vertical line of mean standar
SkiaSharp 之 WPF 自绘 拖曳小球(案例版)
Autumn recruit offer harvesters, and take the offers of major manufacturers at will
Jupiter、spyder、Anaconda Prompt 、navigator 快捷键消失的解决办法
R语言-用于非平衡数据集的一些度量指标
Design and implementation of SSM personal blog system
zotero文献管理器及其使用姿势(不定时更新)
"Node learning notes" koa framework learning
强缓存、协商缓存具体过程
「以云为核,无感极速」第五代验证码重磅来袭