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 |
My solve1.求区间的和,easy!sum[i]=sum[i-1]+date[i]; 2.求区间最小值,难道要一个个区间求吗?No! 反过来,求以date[i]为最小值的左右边界即可! 3.求Min(date[i])的左右边界,用lef[i],rig[i]保存;栈中元素为下标, 满足条件date[stack[i]]<date[stack[top]] top = 1; stack[top]= 1; stack[0]= 0; lef[1]=1; for (i = 2; i <= N; i++) { while(top && date[stack[top]] >= date[i]) top--; lef[i] = stack[top]+1; stack[++top] = i; } 同样方法求rig[i]; 枚举最小值,OK... 注意求最大值是,maxAns的初始值应设为 -1,我开始设为0,wa了一次,从下面数据发现的: 1 0 3 0 0 0 -------vasile Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator