你最愿意做的哪件事,才是你的天赋所在

0%

10-3训练总结

总结

教训

今天早上打了一套codeforces,然后下午打牛客的训练题目,都是读错了题意,然后思路开始走歪,渐渐的就没了,先挂上题目链接。

题目链接

codeforces 586
牛客国庆训练day3

牛客K

思路

一开始竟然用NTT的三模运算来写,复杂度8nlogn*T,很显然,这题出题人特意卡了这个复杂度。
看了题解后发现,这是一道前缀和的题目,写出式子后提取公因式乘法就能解决了。
每次看到题后先考虑方向的正确性再去考虑做法会更好

代码实现

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 5e5+10;
const int md = 1e9+7;
int a[maxn];
int b[maxn];
ll pre[maxn];
int main()
{
int n,m,l,r;
while(scanf("%d %d %d %d",&n,&m,&l,&r)!=EOF)
{
for(int i=0;i<=n;i++)scanf("%d",&a[i]);
for(int i=0;i<=m;i++)scanf("%d",&b[i]);
long long ans = 0;
long long temp = 0;
for(int i=l;i<=r&&i<=m;i++)temp=(temp+b[i])%md;
for(int i=0;i<=n;i++)
{
ans=(ans+a[i]*temp)%md;
l--;
if(l>=0&&l<=m)temp=(temp+b[l])%md;
if(r>=0&&r<=m)temp=(temp-b[r]+md)%md;
r--;
}
cout<<ans<<endl;
}
}
-------------你最愿意做的哪件事才是你的天赋所在-------------