【題解】[牛客網NOIP賽前集訓營-提高組(第四場)]B.區間 亂搞
阿新 • • 發佈:2018-11-01
#include<cstdio> #include<algorithm> using namespace std; typedef long long ll; const int MAXN=1e7+10; ll a[MAXN]; int r[MAXN],N,ans=1; #define RG register #define getc() (S == T && (T = (S = B) + fread(B, 1, 1 << 15, stdin), S == T) ? EOF : *S++) char B[1 << 15], *S = B, *T = B; inline long long F() { RG char ch; RG long long x = 0; RG bool m = 0; while (ch = getc(), (ch < '0' || ch > '9') && ch != '-') ; ch == '-' ? m = 1 : x = ch - '0'; while (ch = getc(), ch >= '0' && ch <= '9') x = x * 10 + ch - '0'; return m ? -x : x; } int main() { //freopen("in.txt","r",stdin); N=F();ll v; for(int i = 1; i <= N; ++i) a[i] = F(); for(int i = 1, j = 1; i <= N; ++i) {v = a[i]; while(j <= N && a[j] % v == 0) ++j; r[i] = j;} for(int i = N, j = N; i >= 1; --i) {v = a[i]; while(j >= 1 && a[j] % v == 0) --j; if(r[i] - j - 1 > ans) ans = r[i] - j - 1;} printf("%d\n",ans); return 0; }
總結
無