1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| #include<iostream> #include<cstdio> #include<cstring> #include<stack>
#define REP(i,e,s) for(register int i=e; i<=s; i++) #define DREP(i,e,s) for(register int i=e; i>=s; i--) #define DE(...) fprintf(stderr,__VA_ARGS__) #define DEBUG(a) DE("DEBUG: %d\n",a) #define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout) using namespace std; #define ll long long #define int ll
int read() { int x=0,f=1,ch=getchar(); while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; }
const int MAXN=100000+10,INF=0x3f3f3f3f;
int a[MAXN];
namespace Solution { int ans[MAXN]; void main() { int n=read(); REP(i,1,n) a[i]=read();
REP(i,1,n) { ans[1]=max(ans[1],1ll*a[i]*a[i]);
int minn=a[i],maxx=a[i],l=i,r=i; while(a[l]<=maxx&&a[r]<=maxx) { if(a[l-1]>a[r+1]) l--; else r++; if(r>n) r--; if(l<1) l++; minn=min(minn,min(a[l],a[r])); ans[r-l+1]=max(ans[r-l+1],1ll*maxx*minn); if(l==1&&r==n) break; } } REP(i,1,n) printf("%lld\n",ans[i]); } } signed main() { Solution::main(); return 0; }
|