POJ-2796-Feel Good

区间合并用并查集做~

代码:

#include
#include
#include
#include
using namespace std;
const int maxn=1e5+10000;
const int inf=1<<29;
struct Node{
    int val;
    int index;
    bool operator < (const Node &a)const{
        return val=0;i--)
        {
            vis[a[i].index]=1;
            int x=find(a[i].index);
            sum[x]+=a[i].val;
            ansl[x]=ansr[x]=a[i].index;
            if(sum[x]*a[i].val>ans)
            {
                ans=sum[x]*a[i].val;
                ansleft=ansl[x];
                ansright=ansr[x];
            }
            if(a[i].index>0&&vis[a[i].index-1])
            {
                int y=find(a[i].index-1);
                sum[x]+=sum[y];
                ansl[x]=min(ansl[x],ansl[y]);
                ansr[x]=max(ansr[x],ansr[y]);
                p[y]=x;
            }
            if(a[i].indexans)
            {
                ans=sum[x]*a[i].val;
                ansleft=ansl[x];
                ansright=ansr[x];
            }
        }
        printf("%I64d\n%d %d\n",ans,ansleft+1,ansright+1);
    } 
    return 0;
}


你可能感兴趣的:(POJ,ACM)