• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
Aropm
博客园    首页    新随笔    联系   管理    订阅  订阅

【nowcoder】 4th T2 区间

题目链接:https://www.nowcoder.com/acm/contest/175/B

当你为时间复杂度挠头的时候 别人已经33行拿满分了

 

 1 #include<cstdio>
 2 #include<algorithm>
 3 #define N 4000010
 4 using namespace std;
 5 typedef long long ll;
 6 
 7 ll Read(){
 8     ll xx=0,ff=1;char ch=getchar();
 9     while(ch>'9'||ch<'0') {if(ch=='-') ff=-1;ch=getchar();}
10     while(ch<='9'&&ch>='0') {xx=(xx<<3)+(xx<<1)+ch-'0';ch=getchar();}
11     return xx*ff;
12 }
13 
14 ll n,inp[N];
15 int res,ans[N];
16 
17 int main(){
18     n=Read();
19     for(register int i=1;i<=n;i++)
20     inp[i]=Read();
21     for(register int i=1,r=1;i<=n;++i){
22         if(r<i) r=i;
23         while(r<n&&inp[r+1]%inp[i]==0) r++;
24         ans[i]=r;
25     }
26     for(register int i=n,l=n;i>0;--i){
27         if(l>i) l=i;
28         while(l>1&&inp[l-1]%inp[i]==0) l--;
29         res=max(res,ans[i]-l+1);
30     }
31     printf("%d",res);
32     return 0;
33 }

 

posted on 2018-10-08 14:46  Aropm  阅读(93)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3