• ACdream群(167655270)原创群赛(3) 1028 Problem G Multiplication


    1028: Multiplication
    Time Limit: 2 Sec  Memory Limit: 128 MB
    Submit: 547  Solved: 126
    [Submit][Status][Web Board]
    Description
    
    If C=A⋄B, then
    C[k]=∑max(i,j)=kA[i]⋅B[j]mod(109+7)
    .
    
    Work out sequence C=A⋄B for given sequence A and B.
    Input
    
    The first line contains a integer n, which denotes the length of sequence A,B.
    
    The second line contains n integers a1,a2,…,an, which denote sequence A.
    
    The thrid line contains n integers b1,b2,…,bn, which denote sequenceB.
    
    (1≤n≤105,0≤ai,bi≤109)
    Output
    
    n integers, which denotes sequence C.
    Sample Input
    2 1 2 3 4
    Sample Output
    3 18
    HINT
    
    Source
    
    ftiasch

    http://www.acdream.net/problem.php?id=1028

    O(n^2) 算法是肯定超时的
    想下就可以发现这样就是可以用O(N)的算法 记录前i个数和就可以了

    #include <iostream>
    #include <stdio.h>
    #include <queue>
    #include <stack>
    #include <set>
    #include <vector>
    #include <math.h>
    #include <string.h>
    #include <algorithm>
    using namespace std;
    #define N 100002
    #define Max 1000000007
    #define __int64 long long
    __int64 a[N],b[N],aa[N],bb[N];
    int main()
    {
        int n;
        int i;
        while(scanf("%d",&n)!=EOF)
        {
            for(i=1;i<=n;i++)
             {
                 scanf("%lld",&a[i]);
                 aa[i]=aa[i-1]+a[i];
             }
            for(i=1;i<=n;i++)
             {
                 scanf("%lld",&b[i]);
                 bb[i]=bb[i-1]+b[i];
             }
           __int64 ans;
           printf("%lld",a[1]*b[1]%Max);
           for(i=2;i<=n;i++)
           {
               ans=(a[i]*(bb[i-1]%Max)+b[i]*(aa[i-1]%Max)+a[i]*b[i]%Max)%Max;
               printf(" %lld",ans);
           }
        printf("\n");
        }
        return 0;
    }
  • 相关阅读:
    C++引用之引用的使用
    C++引用之声明方法
    C++const与指针
    C++默认参数值函数
    LeanCloud 调研报告
    [译] 为何流处理中局部状态是必要的
    Z-Stack
    Think twice before starting the adventure
    Multi-pattern string match using Aho-Corasick
    C pointer again …
  • 原文地址:https://www.cnblogs.com/372465774y/p/2779485.html
Copyright © 2020-2023  润新知