当前位置:网站首页>[nk] Niuke monthly competition 51 f-average question
[nk] Niuke monthly competition 51 f-average question
2022-06-10 21:46:00 【*DDL_ GzmBlog】
Preface
T a g : Tag : Tag: mathematics thinking law The prefix and
Portal :
The question :
Give you an array , You need to figure out Sum of all sub segment averages
The answer is right 1 0 9 + 7 10^9+7 109+7 modulus , If the simplest answer is a b \frac{a}{b} ba, Then you need to find the smallest nonnegative integer x x x bring x × b ≡ a ( 1 0 9 + 7 ) x×b\equiv a(10^9+7) x×b≡a(109+7)
Ideas :
We consider the interval of operations Length classification , namely t = 1 , 2.... n t=1,2....n t=1,2....n
t = 1 t=1 t=1
The obvious answer is S n S_n Sn( Represents the prefix and )
t = 2 t=2 t=2
The answer is S n + S n − 1 − S 1 S_n+S_{n-1}-S_{1} Sn+Sn−1−S1
… The rest is the same

So we can O ( n ) O(n) O(n) Find out the value of each segment
At the end of the statistics , We find one for each paragraph Multiply the inverse , The denominator
code :
ll qmi(ll a,ll b){
ll res = 1;
while(b){
if(b&1) res = res*a%mod;
a = a*a%mod;
b>>=1;
}
return res;
}
ll n,a[N],pre[N],dp[N];
void solve(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>pre[i];
pre[i] = (pre[i] + pre[i-1])%mod;
}
for(int i=1;i<=n;i++){
if(i<=n/2+n%2)
dp[i] = (dp[i-1] + (pre[n+1-i] - pre[i - 1] + mod))%mod;
else dp[i] = dp[n+1-i];
}
ll ans = 0;
for(int i=1;i<=n;i++){
ans = (ans + dp[i]*qmi(i,mod-2))%mod;
}
cout<<ans<<endl;
}
边栏推荐
- Leetcode advanced path - reverse string
- 初中毕业生,选择中职学校也可以升入高等学府
- Understanding deep learning attention
- In 2021, the average salary will be released, and the IT industry will not be surprised
- C language -- 7 operators
- Video monitoring system storage control, bandwidth calculation method
- 编程式导航路由跳转到当前路由(参数不变), 多次执行会抛出NavigationDuplicated的警告错误?
- Meetup Preview: introduction to the new version of linkis and the application practice of DSS
- Nanny tutorial: how to become a contributor to Apache linkis documents
- Mysql之将查询结果插入到其它表中
猜你喜欢

Understanding of related concepts of target detection

App test case

A small case with 666 times performance improvement illustrates the importance of using indexes correctly in tidb

1、 Vulkan develops theoretical fundamentals

Notes to entry: do I need to know programming for O & M?
php伪协议实现命令执行详情

Use DAP link to download the executable file separately to the mm32f5 microcontroller

Acl2022 | bert2bert: an efficient pre training method of parameter reuse, which significantly reduces the training cost of oversized models

Meetup Preview: introduction to the new version of linkis and the application practice of DSS

登堂入室之soc开发环境及硬件开发准备
随机推荐
C language ---2 initial knowledge of data types
Notes to entry: do I need to know programming for O & M?
C language ---6 first knowledge of selection statement, loop statement, function and array
How to choose the field of we media video creation?
Self made table
Course design of imitation pottery ticket of wechat applet
Practical | how to use burp suite for password blasting!
SoC development environment and hardware development preparation
异步、线程池(CompletableFuture)
Extracting Nalu unit data from H264 real-time stream
app測試用例
Mysql之將查詢結果插入到其它錶中
Codeforces Round #798 (Div. 2)
^29事件循环模型
Rotate menu 3.0
LeetCode 进阶之路 - 136.只出现一次的数字
Read the source code of micropyton - add the C extension class module (2)
app测试用例
蛮力法/1~n个整数中取k个整数
蛮力法/1~n的幂集 v4 递归