zoukankan      html  css  js  c++  java
  • bzoj 4052: [Cerc2013]Magical GCD

    bzoj4488的双倍经验!!

     1 #include <bits/stdc++.h>
     2 #define LL long long
     3 using namespace std;
     4 inline LL ra()
     5 {
     6     LL x=0; char ch=getchar();
     7     while (ch<'0' || ch>'9') ch=getchar();
     8     while (ch>='0' && ch<='9') {x=x*10+ch-'0';ch=getchar();}
     9     return x;
    10 }
    11 
    12 const int maxn=100005;
    13 
    14 struct node{
    15     LL num; int x;
    16     bool operator < (const node &y) const {return num<y.num||num==y.num && x<y.x;}
    17 }f[2][maxn];
    18 LL a[maxn];
    19 int n;
    20 
    21 LL gcd(LL x, LL y) {return y==0?x:gcd(y,x%y);}
    22 
    23 int main()
    24 {
    25     int T=ra();
    26     while (T--)
    27     {
    28         n=ra(); 
    29         for (int i=1; i<=n; i++) a[i]=ra();
    30         int s1=0,s2=0;
    31         int p=0,q=1;
    32         LL ans=0; node d;
    33         for (int i=1; i<=n; i++)
    34         {
    35             for (int j=1; j<=s1; j++) f[p][j].num=gcd(a[i],f[p][j].num);
    36             d.num=a[i]; d.x=i; s1++; f[p][s1]=d;
    37             sort(f[p]+1,f[p]+s1+1);
    38             s2=0;
    39             for (int j=1; j<=s1; j++)
    40                 if (f[p][j].num!=f[p][j-1].num)
    41                     f[q][++s2]=f[p][j];
    42             for (int j=1; j<=s2; j++) ans=max(ans,f[q][j].num*(LL)(i-f[q][j].x+1));
    43             p^=1; q^=1; s1=s2;
    44         }
    45         printf("%lld
    ",ans);
    46     }
    47     return 0;
    48 }
  • 相关阅读:
    Linux系统下安装jdk1.8并配置java环境
    linux常用命令
    intelliJ IDEA 中快速定位当前文件路径
    Intellij IDEA 入门之java “Hello word”
    常用SQL语句
    PictureBox的内存问题
    MDI窗体设计
    实现多态的方法三——接口
    css清除浮动方法
    三栏式布局(下)
  • 原文地址:https://www.cnblogs.com/ccd2333/p/6792658.html
Copyright © 2011-2022 走看看