超时蒟蒻求助

P1567 统计天数

题中N最大可以到10^6,你的程序的时间复杂度是O(n^2)的,对于大规模数据过不了 可以考虑优化到O(n)
by hundunqidian @ 2023-10-30 21:42:28


```cpp #include <iostream> #include <cstdio> #include <cmath> using namespace std; const int MAXN=1000*1000; int a[MAXN]; int n,m,ans; int t=1; int line(int x) { if(a[x]>a[x-1]) t++; else t=1; return t; } int main() { cin>>n; for (int i=1;i<=n;i++) { cin>>a[i];ans=max(ans,line(i)); } cout<<ans; return 0; } ``` 复杂度太高,$O(n)$ 就行。
by Ehuo_ovo @ 2023-10-30 21:45:56


|