Bob's vector
题目连接:
http://acm.uestc.edu.cn/#/problem/show/1048
Description
Bob has a vector with mm elements, called vector BB. Now Alice gives him a vector XX with nn elements.
Then he gets a new vector AA, in which Ai=(B1×Xi+B2×X2i⋯+Bm−1×Xm−1i+Bm×Xmi)Ai=(B1×Xi+B2×Xi2⋯+Bm−1×Xim−1+Bm×Xim) mod 10000000071000000007.
Now Alice wants to find a peak position in vector AA, and a peak position is a position whose value is greater than both of its neighbors. You may assume that A0=−∞,An+1=−∞A0=−∞,An+1=−∞.
As is known to everyone of you, Bob loves Alice very much. Could you tell Bob the answer to help Bob leave a good impression on Alice.
Input
The frist line contains 22 integers n,mn,m, indicating the size of vector XX and the size of vector BB.
The second line contains nn integers Xi(0≤Xi≤1000000000)Xi(0≤Xi≤1000000000), indicating the element in the vector XX.
The last line contains mm integers Bi(0≤Bi≤1000000000)Bi(0≤Bi≤1000000000), indicating the element in the vector BB.
It is guaranteed that 1≤n≤500000,1≤m≤100001≤n≤500000,1≤m≤10000, and Ai≠Ai+1(1≤i<n)Ai≠Ai+1(1≤i<n) .
Output
Print a single integer, which denotes a peak position. If there are multiple solutions, you may print any of them.
Sample Input
3 2
2 1 3
1 1
Sample Output
1
Hint
题意
给你一个计算ai的方法
假设f(i) = ai
让你求这个函数的峰值在哪儿。
题解:
肯定不能暴力算出所有ai嘛
这个就像爬山算法一样,一直往高处爬就好了,于是瞎逼三分就完了……
不过这道题数据太水了,怎么写怎么过……
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 5e5+7;
const int mod = 1e9+7;
int n,m;
long long x[maxn],b[maxn];
long long quickpow(long long m,long long n,long long k)//返回m^n%k
{
long long b = 1;
while (n > 0)
{
if (n & 1)
b = (b*m)%k;
n = n >> 1 ;
m = (m*m)%k;
}
return b;
}
long long get(int p)
{
if(p==0)return -1e9;
if(p==n+1)return -1e9;
long long ans = 0;
for(int i=1;i<=m;i++)
ans = (ans + b[i]*quickpow(x[p],i,mod))%mod;
return ans;
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
scanf("%lld",&x[i]);
for(int i=1;i<=m;i++)
scanf("%lld",&b[i]);
int l = 1,r = n;
while(l<r-10)
{
int midl = (l+l+r)/3;
int midr = (l+r+r)/3;
long long p1 = get(midl);
long long p2 = get(midr);
if(p1>p2)r=midr;
else l=midl;
}
for(int i=l;i<=r;i++)
{
if(get(i)>get(i-1)&&get(i+1)<get(i))
{
printf("%d
",i);
return 0;
}
}
}