当前位置:网站首页>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;
}
边栏推荐
- MySQL (version 8.0.16) command and description
- 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
- 强缓存、协商缓存具体过程
- Function of interface test
- LabVIEW AI visual Toolkit (non Ni vision) download and installation tutorial
- Boutique scheme | Haitai Fangyuan full stack data security management scheme sets a "security lock" for data
- 使用c语言实现双向链表
- [cesium] entity property and timing binding: the sampledproperty method is simple to use
- I/O实操之对象流(序列化与反序列化)
- Database advanced learning notes cursor
猜你喜欢

Learning notes tree array

What is the process of switching c read / write files from user mode to kernel mode?

可视化大型时间序列的技巧。
![Two point, three point, 01 point plan [bullet I]](/img/12/5cc55b5f4f0bbcd5b89a9601eed824.png)
Two point, three point, 01 point plan [bullet I]

Today's sleep quality record 74 points

Outlook suddenly becomes very slow and too laggy. How to solve it

Are interviews all about memorizing answers?

A hundred flowers bloom in data analysis engines. Why invest heavily in Clickhouse?

zotero文献管理器及其使用姿势(不定时更新)

LabVIEW AI visual Toolkit (non Ni vision) download and installation tutorial
随机推荐
数字孪生轨道交通:“智慧化”监控疏通城市运行痛点
What is the process of switching c read / write files from user mode to kernel mode?
Xiaoshuidi 2.0 website navigation network template
WPF layout controls are scaled up and down with the window, which is suitable for multi-resolution full screen filling applications
PKG packaging node project
Today's sleep quality record 74 points
Thinkphp5 behavior hook return result (data) example
AlexNet—论文分析及复现
Random talk on GIS data (V) - geographic coordinate system
使用c语言实现双向链表
Good use explosion! The idea version of postman has been released, and its functions are really powerful
学会使用MySQL的Explain执行计划,SQL性能调优从此不再困难
CVPR2021 行人重识别/Person Re-identification 论文+开源代码汇总
Flutter tutorial flutter navigator 2.0 with gorouter, use go_ Router package learn about the declarative routing mechanism in fluent (tutorial includes source code)
Summary of common RSA related problems in CTF: basic RSA encryption and decryption
CVPR2020 best paper:对称可变形三维物体的无监督学习
可视化大型时间序列的技巧。
R language uses dplyr package group_ By function and summarize function calculate the mean value of all covariates involved in the analysis based on grouped variables (difference in means of covariate
mysql(8.0.16版)命令及说明
Embrace open source guidelines