区间 题解
题意简述
求长度为
题目分析
根据
我们直接扫是
代码
#include <cstdio> const int MAX = 1 << 28; char buf[MAX], *p = buf; #ifdef XuYueming # define fread(_, __, ___, ____) #else # define getchar() *p++ #endif #define isdigit(x) ('0' <= x && x <= '9') #define __yzh__(x) for (; x isdigit(ch); ch = getchar()) template <typename T> inline void read(T &x) { x = 0; char ch = getchar(); __yzh__(!); __yzh__( ) x = (x << 3) + (x << 1) + (ch ^ 48); } const int N = 4000010; using lint = long long; int n, ans, stack[N], *top = stack, L[N], *Li = L; lint val[N]; signed main() { #ifndef XuYueming freopen("interval.in", "r", stdin); freopen("interval.out", "w", stdout); #endif fread(buf, 1, MAX, stdin); read(n); register int i; for (i = 1; i <= n; ++i) { read(val[i]); while (top != stack && val[*top] % val[i] == 0) --top; *++Li = *top + 1, *++top = i; } *(top = stack) = n + 1; for (i = n; i; --i) { while (top != stack && val[*top] % val[i] == 0) --top; if (*top - *Li > ans) ans = *top - *Li; *++top = i, --Li; } printf("%d", ans); return 0; }
本文作者:XuYueming,转载请注明原文链接:https://www.cnblogs.com/XuYueming/p/18444415。
若未作特殊说明,本作品采用 知识共享署名-非商业性使用 4.0 国际许可协议 进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探
· 为什么 退出登录 或 修改密码 无法使 token 失效