HDU5288——OO’s Sequence(2015多校-1001)

http://acm.hdu.edu.cn/showproblem.php?pid=5288

一句话,这题目就是考智商的题。。。可怜我这个新手智商低~T_T

言归正传:题意很容易理解,就是讲一个数组的可以组成的所有区间的,该区间所有不能整除该区间其他数的个数的和。

解决办法就是:找到一个数的左右最近的两个值恰好为该数的因子的位置分别为L[i],R[i],那么在区间(L[i],R[i])内a[i]是该区间的一个所有数的值都不能整除该数的值。所以a[i]可以作为答案的个数为(L[i]-i)*(i-R[i])

先写个超时的~

#include<stdio.h>
#include<string.h>
int summary();
int L[100010],R[100010],a[100010],n;
int main(){
    freopen("1001.in","r",stdin);
    while(scanf("%d",&n)!=EOF){
            memset(a,0,sizeof(a));
            memset(L,0,sizeof(L));
            memset(R,0,sizeof(R));
        for(int i=0;i<n;i++){
            scanf("%d",&a[i]);
            L[i]=R[i]=i;
        }
        printf("%I64d\n",summary());
    }
}
int summary(){
    int sum=0;
    for(int i=0;i<n;i++){
        for(int j=i-1;j>=0;j--){
                L[i]=j;
            if(a[i]%a[j]==0){
                break;
            }
            if(j==0)L[i]=j+1;
        }
        for(int j=i+1;j<n;j++){
             R[i]=j;
            if(a[i]%a[j]==0){
                break;
            }
            if(j==n-1)R[i]=j+1;
        }
        if(i==0)sum+=(R[i]-i)%1000000007;
        else if(i==n-1) sum+=i-L[i]%1000000007;
        else sum+=(i-L[i])*(R[i]-i)%1000000007;
      // printf("%d %d %d %d\n",sum,L[i],R[i],i);
    }
return sum;
}

原文地址:https://www.cnblogs.com/Yvettey-me/p/4674386.html

时间: 2024-11-13 17:27:47

HDU5288——OO’s Sequence(2015多校-1001)的相关文章

HDU 5288 OO&#39;s sequence (2015多校第一场 二分查找)

OO's Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 955    Accepted Submission(s): 358 Problem Description OO has got a array A of size n ,defined a function f(l,r) represent the nu

OO’s Sequence 2015多校联合1001

题意:给一个n,然后n个数,求∑i=1n∑j=inf(i,j) mod (109+7). 也就是求n*(n+1)/2个区间内,给定一个i,使得i的左右两边的数都不能被a[i] eg. 5 1 2 3 4 5 一个有5*6/2=15个区间即15个f[l,r] [1,1] [1,2] [1,3] [1,4][1,5] [2,2] [2,3] [2,4][2,5] [3,3] [3,4][3,5] [4,4][4,5] [5,5] 设总数为sum 对于区间[1,1] 其中当i=1时,左右没有数被他整除

解题报告 之 HDU5288 OO&#39; s Sequence

解题报告 之 HDU5288 OO' s Sequence Description OO has got a array A of size n ,defined a function f(l,r) represent the number of i (l<=i<=r) , that there's no j(l<=j<=r,j<>i) satisfy a imod a j=0,now OO want to know () Input There are multipl

HDU 5288 OO’s Sequence(多校第一场1001)

OO's Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 900    Accepted Submission(s): 339 Problem Description OO has got a array A of size n ,defined a function f(l,r) represent the nu

Hdu 5288 OO’s Sequence 2015多小联赛A题

OO's Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 1751    Accepted Submission(s): 632 Problem Description OO has got a array A of size n ,defined a function f(l,r) represent the n

HDU5288 OO’s Sequence

Problem Description OO has got a array A of size n ,defined a function f(l,r) represent the number of i (l<=i<=r) , that there's no j(l<=j<=r,j<>i) satisfy ai mod aj=0,now OO want to know ∑i=1n∑j=inf(i,j) mod (109+7). Input There are mul

hdu5288 OO’s Sequence(质因子分解+二分)

题目:http://acm.hdu.edu.cn/showproblem.php?pid=5288 题意:区间[L,R],若L<=i<=R,对于所有的i,满足a[i]%a[j]!=0(i!=j)则i对答案的贡献+1.求出所有区间的答案和,其中1<=L<=R<=N. 分析:求出每个数对答案的贡献即可.对于每个a[i],求左边离a[i]最近且可以整出a[i]的位置L[i]和右边离a[i]最近且可以整出a[i]的位置R[i],那么a[i]对答案的贡献就是(R[i]-i)*(i-L[

解题报告 之 HDU5288 OO&amp;#39; s Sequence

解题报告 之 HDU5288 OO' s Sequence Description OO has got a array A of size n ,defined a function f(l,r) represent the number of i (l<=i<=r) , that there's no j(l<=j<=r,j<>i) satisfy a imod a j=0,now OO want to know Input There are multiple t

hdu5288(2015多校1)OO’s Sequence

OO's Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 353    Accepted Submission(s): 117 Problem Description OO has got a array A of size n ,defined a function f(l,r) represent the nu