# luogu3932 浮游大陆的68号岛

x×dist(i,j)x \times \mathrm{dist}( i , j )x×dist(i,j)

dist就是仓库间的距离。

5 5
2 3 4 5
1 2 3 4 5
1 1 5
3 1 5
2 3 3
3 3 3
1 5 5

125
72
9
0
70

#include<cstdio>
#define mod 19260817
#define N 220000
inline char gc(){
static char now[1<<16],*S,*T;
return *S++;
}
int x=0;char ch=gc();
while (ch<'0'||ch>'9') ch=gc();
while (ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=gc();}
return x;
}
long long sigma_weigh2[N],sigma_weigh1[N],sigma_dis1[N],sigma_dis2[N],ans,cost1[N],cost2[N];
int x,l,r,n,m,dis[N],weigh[N];
int main(){
freopen("13375.in","r",stdin);
freopen("ex.out","w",stdout);
for (int i=n;i>=1;--i) sigma_weigh2[i]=(sigma_weigh2[i+1]+weigh[i])%mod;
for (int i=n;i>1;--i) sigma_dis2[i-1]=(sigma_dis2[i]+dis[i-1])%mod;
for (int i=1;i<=n;++i) cost1[i]=(cost1[i-1]+sigma_weigh1[i-1]*dis[i-1]%mod)%mod;
for (int i=n;i>=1;--i) cost2[i]=(cost2[i+1]+sigma_weigh2[i+1]*dis[i]%mod)%mod;
for (int i=1;i<=m;++i){
if (x>=l&&x<=r){
(ans+=cost1[x]-cost1[l-1]-sigma_weigh1[l-1]*((sigma_dis1[x]-sigma_dis1[l-1]+mod)%mod)%mod)%=mod;ans+=mod;ans%=mod;
(ans+=cost2[x]-cost2[r+1]-sigma_weigh2[r+1]*((sigma_dis2[x]-sigma_dis2[r+1]+mod)%mod)%mod)%=mod;ans+=mod;ans%=mod;
}
if (x<l){
(ans=cost2[x]-cost2[r+1]-sigma_weigh2[r+1]*((sigma_dis2[x]-sigma_dis2[r+1]+mod)%mod)%mod)%=mod;ans+=mod;ans%=mod;
(ans-=cost2[x]-cost2[l]-sigma_weigh2[l]*((sigma_dis2[x]-sigma_dis2[l]+mod)%mod)%mod)%=mod;ans+=mod;ans%=mod;
}
if (x>r){
(ans=cost1[x]-cost1[l-1]-sigma_weigh1[l-1]*((sigma_dis1[x]-sigma_dis1[l-1]+mod)%mod)%mod)%=mod;ans+=mod;ans%=mod;
(ans-=cost1[x]-cost1[r]-sigma_weigh1[r]*((sigma_dis1[x]-sigma_dis1[r])%mod)%mod)%=mod;ans+=mod;ans%=mod;
}
printf("%lld\n",ans);
}
return 0;
}



• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120