6058 Kanade's sum ????????????()

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了6058 Kanade's sum ????????????()相关的知识,希望对你有一定的参考价值。

?????????--   i++   can   lld   ??????   ??????   color   its   scanf   

??????:???????????????[1,n]?????????a,??????f[l,r,k]?????????[l,r]??????k????????????.
??????k,??? ?????????(l=1~n,r~l~n)f[l,r,k] . n<=5e5,k<=min(80,n)
k<=80 a[i]??????: ???????????????p????????????,????????????k-1-p????????????.
??????????????????/?????????p??????????????????????
???????????????????????????,??????????????????,??????????????????,?????????x???,??????????????????x?????????

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+5;
int a[N],b[N],n,k;
int pre[N],nxt[N],pos[N];
ll solve(int x)
{
    int c1=0,c2=0;
    for(int i=x;i&&c1<=k;i=pre[i])
        a[++c1]=i-pre[i];
    for(int i=x;i<=n&&c2<=k;i=nxt[i])
        b[++c2]=nxt[i]-i;
    ll res=0;
    for(int i=1;i<=c1;i++)
    {
        if(c2>=k-i+1&&k-i+1>=1)
            res+=a[i]*b[k-i+1];
    }
    return res;
}
void del(int x)
{
    pre[nxt[x]]=pre[x];
    nxt[pre[x]]=nxt[x];
}
int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        int x;
        scanf("%d%d",&n,&k);
        for(int i=1;i<=n;i++)
            scanf("%d",&x),pos[x]=i;
        ll ans=0;
        for(int i=0;i<=n+1;i++)
            pre[i]=i-1,nxt[i]=i+1;
        pre[0]=0,nxt[n+1]=n+1;
        for(int i=1;i<=n;i++)
        {
            ans+=i*solve(pos[i]);
            del(pos[i]);
        }    
        printf("%lld\n",ans);
    }
    return 0;
} 

 

以上是关于6058 Kanade's sum ????????????()的主要内容,如果未能解决你的问题,请参考以下文章

HDU 6058 Kanade's sum(链表)

HDU 6058 Kanade's sum —— 2017 Multi-University Training 3

链表2017多校训练3 HDU 6058 Kanade's sum

HDU-6057 Kanade's convolution

hdu6059 Kanade's trio 字典树+容斥

HDU 6057 Kanade's convolution