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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
| #include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<cstdlib> #include<algorithm> #include<ctime> #include<iomanip> #include<queue> #include<stack> #include<map> #include<vector> #define gh() getchar() #define underMax(x,y) ((x)>(y)?(x):(y)) #define underMin(x,y) ((x)<(y)?(x):(y)) typedef long long ll; using namespace std; const int MAXN=1e6+1; const int INF=1e9; template<class T> inline void underRead(T &x) { x=0; char ch=gh(),t=0; while(ch<'0'||ch>'9') t|=ch=='-',ch=gh(); while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=gh(); if(t) x=-x; } int T,n,v[MAXN<<2],a[MAXN],g[MAXN],f[MAXN],b[MAXN]; inline void underBuild(int p,int l,int r) { v[p]=0; if(l==r) return ; int mid=(l+r)>>1; underBuild(p<<1,l,mid),underBuild(p<<1|1,mid+1,r); } inline void underModify(int p,int l,int r,int x,int d) { v[p]=underMax(v[p],d); if(l==r) return ; int mid=(l+r)>>1; if(x<=mid) underModify(p<<1,l,mid,x,d); if(mid<x) underModify(p<<1|1,mid+1,r,x,d); } inline int underQuery(int p,int l,int r,int x,int y) { if(x<=l&&r<=y) return v[p]; int mid=(l+r)>>1,ans=0; if(x<=mid&&y>=l) ans=underQuery(p<<1,l,mid,x,y); if(y>mid&&x<=r) ans=underMax(ans,underQuery(p<<1|1,mid+1,r,x,y)); return ans; } int h[MAXN],tot,Max,Dp,t[MAXN]; struct Node { int l,r; }num[MAXN]; inline void underWork() { memset(b,0x7f7f7f7f,sizeof(b)); a[0]=a[n+1]=0; for(int i=1;i<=n;++i) { a[i]=h[i]; g[i]=1; if(a[i]>a[i-1]) g[i]=g[i-1]+1; } int ans=0,dp=0; for(int i=n;i;--i) { f[i]=1; if(a[i]<a[i+1]) f[i]=f[i+1]+1; } for(int i=1;i<=n;++i) if(ans<underMax(f[i],g[i])) { ans=underMax(f[i],g[i]); dp=i; }
b[1]=a[1]; for(int i=1;i<=n;++i) { int k=lower_bound(b+1,b+1+n,a[i])-b-1; if(f[i]+k>ans) { ans=f[i]+k; dp=i; } b[g[i]]=underMin(b[g[i]],a[i]); }
printf("%d %d",dp+f[dp]-1,ans); }
int main() { freopen("sentry.in","r",stdin); freopen("sentry.out","w",stdout); underRead(n); num[++tot].l=1; for(int i=1;i<=n;++i) { underRead(h[i]); if(h[i-1]>=h[i]) { num[tot].r=i-1; num[++tot].l=i; } t[i]=tot; } num[tot].r=n; if(tot==1) { printf("%d\n%d %d",n,n,n); return 0; } if(tot==n) { printf("1\n1 1"); return 0; } int maxn=0,dp=1; for(int i=1;i<=tot;++i) { int k=num[i].r-num[i].l+1; if(k>maxn) { maxn=k; dp=num[i].r; } } printf("%d\n",dp); underWork(); return 0; }
|