• BZOJ 4488/4052 gcd


    思路:

    一开始 我是想 对于固定的左端点 从左到右 最多有 log种取值  且单调递减  那不妨倍增预处理+二分GCD在哪变了.. 复杂度O(nlog^2n)

    gcd最多log种取值..

    好了我们可以暴力了...

    复杂度O(nlogn)

    //By SiriusRen
    #include <cstdio>
    #include <algorithm>
    using namespace std;
    typedef long long ll;
    int cases,n,top,temp;
    ll xx,ans;
    struct Node{int id;ll gcd;}jy[33],al[33];
    ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
    int main(){
            scanf("%d",&n),ans=top=0;
            for(int i=1;i<=n;i++){
                scanf("%lld",&xx),temp=0;
                jy[++top].gcd=0,jy[top].id=i;
                for(int j=1;j<=top;j++)jy[j].gcd=gcd(jy[j].gcd,xx);
                for(int j=1;j<=top;j++)if(jy[j].gcd!=jy[j-1].gcd)
                    ans=max(ans,jy[j].gcd*(i+1-jy[j].id)),jy[++temp]=jy[j];
                top=temp;
            }
            printf("%lld\n",ans);
    }
  • 相关阅读:
    系统安全及应用
    进程和计划任务管理
    Java技术体系
    开机十步和进程管理
    Raid
    LVM逻辑卷
    sed命令
    磁盘管理
    你的背景,是这个时代 张璁
    别将梦想停留在二十岁
  • 原文地址:https://www.cnblogs.com/SiriusRen/p/6637677.html
Copyright © 2020-2023  润新知