Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

My solve

Posted by 2008022118 at 2009-12-21 20:01:31 on Problem 2796
1.求区间的和,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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator