Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
求dalao看下为啥会MLE#include<iostream> using namespace std; const int maxn=1000001; struct zhangchen { int max,min; }A[maxn][30]; int B[maxn],C[maxn]; int main() { int n,k; scanf("%d%d",&n,&k); for(int i=1;i<=n;i++) scanf("%d",&A[i][0].max),A[i][0].min=A[i][0].max; for(int j=1;j>0;j++) { if((1<<j)>n)break; for(int i=1;i<=n-(1<<j)+1;i++) { A[i][j].max=max(A[i+(1>>j-1)][j-1].max,A[i][j-1].max); A[i][j].min=min(A[i+(1>>j-1)][j-1].min,A[i][j-1].min); } } int l=1,r=k; for(int i=1;i>0;i++) { if((1<<i)>k) { k=i-1; break; } } while(1) { B[l]=max(A[l][k].max,A[r-(1<<k)+1][k].max); C[l]=min(A[l][k].min,A[r-(1<<k)+1][k].min); l++,r++; if(r>n)break; } for(int i=1;i<l;i++) printf("%d ",C[i]); cout<<endl; for(int i=1;i<l;i++) printf("%d ",B[i]); //system("pause"); return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator