听说灌水区大佬多,求助

灌水区

```cpp #include <iostream> #include <algorithm> #include <cstdio> using namespace std; long long t; long long n, m; long long ans = 0; long long a[100005]; long long logs[100005]; long long dp[100005][100]; inline long long read(long long &a){ int w=0,f=1; char ch=getchar(); for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') f=-1; for(;ch>='0'&&ch<='9';ch=getchar()) w=(w<<3)+(w<<1)+(ch^48); a=w*f; } void write(long long x){ if(x<0) putchar('-'),x=-x; if(x>9) write(x/10); putchar(x%10+'0'); } extern inline long long fgcd(long long x, long long y); long long ask(long long x, long long y){ long long lg = logs[y-x+1]; return fgcd(dp[x][lg], dp[y-(1<<lg)+1][lg]); } inline long long fgcd(long long x, long long y) { if (x % y == 0) { return y; } return fgcd(y, x%y); } int main() { read(t); while (t--) { read(n); logs = -1; ans = 0; for (long long i = 1; i <= n; i++) { read(a[i]); } } return 0; } ``` 应该是这样子
by EARS_TURE @ 2024-04-17 20:03:21


啊啊啊对不起写错了!!!
by EARS_TURE @ 2024-04-17 20:04:07


@[__0__](/user/794507) ```cpp #include<bits/stdc++.h> using namespace std; const int N=1e5+10; #define LL long long queue<int>q,r; int n;LL a[N],res; LL gcd(LL a,LL b){return b==0?a:gcd(b,a%b);} int main() { int T;scanf("%d",&T); while(T--) { scanf("%d",&n);res=0; for(int i=1;i<=n;i++) { scanf("%lld",&a[i]);LL last=0;res=max(res,a[i]); while(!q.empty()) { int x=q.front();q.pop();a[x]=gcd(a[x],a[i]);//x就是最小的满足区间[x,i]的gcd为a[x]的左端点 res=max(res,a[x]*(i-x+1)); if(a[x]==a[last]) continue;//一些左端点就可以合并掉 r.push(x);last=x; } while(!r.empty()) { q.push(r.front()); r.pop(); } if(a[last]!=a[i]) q.push(i);//i也可以作为一个新的左端点 } printf("%lld\n",res); while(!q.empty()) q.pop(); } return 0; } ```
by EARS_TURE @ 2024-04-17 20:06:53


@[EARS_TURE](/user/1080324) 有没有用ST表的做法?因为最近在学倍增。老师要求……
by __0__ @ 2024-04-18 17:32:15


|