简单题。

先把环上的贡献都计算好。然后再计算每一个$capital$ $city$额外做出的贡献值。

假设$A$城市为$capital$ $city$,那么$A$城市做出的额外贡献:$A$城市左边城市$L$和右边城市$R$都不能和$A$做出贡献,之前存在的$capital$ $city$和$A$城市不能做出贡献,要注意的是$L$和$R$中存在$capital$ $city$的情况。剩下的城市都可以和$A$做出贡献。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
} const int maxn=;
int n,k;
LL c[maxn],sum,y,p;
bool f[maxn]; int main()
{
scanf("%d%d",&n,&k);
for(int i=;i<=n;i++) scanf("%lld",&c[i]);
LL ans=; c[n+]=c[]; for(int i=;i<=n;i++) ans=ans+c[i]*c[i+],y=y+c[i];
for(int i=;i<=k;i++)
{
int x; scanf("%d",&x); sum=y;
int L=x-,R=x+; if(L==) L=n; if(R==n+) R=;
sum=sum-c[L]-c[R]-c[x]; sum=sum-p;
if(f[L]) sum=sum+c[L]; if(f[R]) sum=sum+c[R];
ans=ans+c[x]*sum; f[x]=; p=p+c[x];
}
printf("%lld\n",ans);
return ;
}

CodeForces 703B Mishka and trip的更多相关文章

  1. Codeforces 703B. Mishka and trip 模拟

    B. Mishka and trip time limit per test:1 second memory limit per test:256 megabytes input:standard i ...

  2. CodeForces 703A Mishka and trip

    Description Little Mishka is a great traveller and she visited many countries. After thinking about ...

  3. codeforces 703B B. Mishka and trip(数学)

    题目链接: B. Mishka and trip time limit per test 1 second memory limit per test 256 megabytes input stan ...

  4. Codeforces Round #365 (Div. 2) Mishka and trip

    Mishka and trip 题意: 有n个城市,第i个城市与第i+1个城市相连,他们边的权值等于i的美丽度*i+1的美丽度,有k个首都城市,一个首都城市与每个城市都相连,求所有边的权值. 题解: ...

  5. cf703B Mishka and trip

    B. Mishka and trip time limit per test 1 second memory limit per test 256 megabytes input  standard ...

  6. 暑假练习赛 003 F Mishka and trip

    F - Mishka and trip Sample Output   Hint In the first sample test: In Peter's first test, there's on ...

  7. codeforces 703E Mishka and Divisors

    codeforces 703E Mishka and Divisors 题面 给出大小为\(1000\)的数组和一个数\(k\),求长度最短的一个子序列使得子序列的元素之积是\(k\)的倍数,如果有多 ...

  8. Codeforces 703D Mishka and Interesting sum 离线+树状数组

    链接 Codeforces 703D Mishka and Interesting sum 题意 求区间内数字出现次数为偶数的数的异或和 思路 区间内直接异或的话得到的是出现次数为奇数的异或和,要得到 ...

  9. Codeforces 703B (模拟) Mishka and trip

    题目:这里 题意:n个城市,每个城市有个魅力值vi,首先,有n条路将这n个城市连成一个环,1号城市连2号城市,2号连3号****n号连1号城市,每条路的魅力值是其连接的两个城市 的魅力值的乘积,这n个 ...

随机推荐

  1. OC之知识储备篇

    1. Objective-C是基于C语言的. a. 在C语言的基础之上新增了面向对象的语法. b. 将C语言中复杂的.繁琐的语法封装的更为简单. 2. Objective-C程序的源文件的后缀名.m  ...

  2. UITabelview的删除

    删除的效果 Automatic Bottom Fade left middle none right top 简单删除 先删除数据源里的数据,然后再删除cell,否者会报错 let indexPath ...

  3. (一)Harbor安装 -- 企业级Registry仓库

    根据Harbor官方描述: Harbor是一个用于存储和分发Docker镜像的企业级Registry服务器,通过添加一些企业必需的功能特性,例如安全.标识和管理等,扩展了开源Docker Distri ...

  4. iOS BUG的解决

    当iOS程序报这样的错误 ld:261 dulicate symbols for architecture x86_64 clang:error:linker command failed with ...

  5. ECMAScript6之Set结构和Map结构

    set数据结构 ES6提供了一个新的数据结构,Set,Set和Array数组相似,但是Set里没有重复的数据,可以说是一个值的集合. 同时,Set数据结构有以下属性和方法: size:返回成员总数 a ...

  6. feature2d相关

    1.Harris角点检测 是基于灰度图像的角点检测. 灰度变化率函数如下: 其中的w(x,y)为加权函数,可为常数或为高斯函数.之后对E(u,v)进行泰勒级数的展开与化简,最终得到 ,,Ix,Iy是图 ...

  7. eclipse中debug快捷方式

    eclipse中如何跳转到指定行 :ctrl+L  然后输入行数 F5:跳入方法 F6:向下逐行调试 F7:跳出方法 F8:直接跳转到下一个断点 持续更新

  8. Android设置窗体Activity背景透明

    背景透明 style.xml <item name="android:windowBackground">@color/transparent</item> ...

  9. Web流量劫持

    BadTunnel实战之远程劫持任意内网主机流量 http://www.freebuf.com/articles/web/109345.html http://blog.csdn.net/ts__cf ...

  10. Scheme入门

    目前选择的是DrRacket作为IDE,可以去网上搜索下载. 打开软件后,输入如下代码进行 helloworld #lang scheme ;The first program (begin (dis ...