UESTC 1048 Bob's vector【煞笔三分】

来源:互联网 发布:鼠标推荐 知乎 编辑:程序博客网 时间:2024/06/05 22:53

Bob's vector

Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 262143/262143KB (Java/Others)

Submit Status

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 and output

Sample Input

Sample Output

3 2

2 1 3

1 1

1

Hint

A0=−∞,A1=6,A2=2,A3=12,A4=−∞A0=−∞,A1=6,A2=2,A3=12,A4=−∞. So 1133 are both OK

Source

The 13th UESTC Programming Contest Final

 

题目大意:


求出任意一个峰值Ai,使得Ai>Ai+1&&Ai>Ai-1;


思路:


三分可以找一个波浪形状的函数的最大值(最小值)的某一个峰点的位子。


那么这个题就是一个煞笔三分了= =


第一次知道三分还有这种骚操作!


Ac代码:

#include<stdio.h>#include<string.h>using namespace std;#define ll long long intint n,m;ll x[15000000];ll b[15000000];const ll mod=1e9+7;ll kuaisumi(ll a,ll b,ll p){        a%=p;        ll ans=1;        while(b)        {            if(b&1)            {                ans=ans*a;                ans%=mod;            }            a=a*a;            a%=mod;            b/=2;        }        return ans;}ll Slove(int pos){    ll INF=-1000000000000000000;    if(pos==0||pos==n+1)return INF;    ll sum=0;    for(int i=1;i<=m;i++)    {        sum=(sum+(b[i]*kuaisumi(x[pos],i,mod)))%mod;    }    return sum%mod;}int main(){    while(~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;        int r=n;        while(l<r-1)        {            int lm=(l+r)/2;            int rm=(lm+r)/2;            if(Slove(lm)<=Slove(rm))            {                l=lm;            }            else r=rm;        }        for(int i=l;i<=r;i++)        {            if(Slove(i)>Slove(i+1)&&Slove(i)>Slove(i-1))            {                printf("%d\n",i);                break;            }        }    }}