简单题。

先把环上的贡献都计算好。然后再计算每一个$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. php文件上传及头像预览

    php文件上传原理是通过form表单的enctype="multipart/form-data"属性将文件临时放到wamp文件夹中的tmp目录下,再通过后台php 程序将文件保存在 ...

  2. C++ std::stack

    std::stack template <class T, class Container = deque<T> > class stack; LIFO stack Stack ...

  3. PHP集成环境自定义设置PHP版本,同时运行多个php版本,700个PHP版本随时切换,一键开启常用模块。

    本文采用我自己开发的纯绿色版WAMP环境(我将这个WAMP环境命名为PHPWAMP) (PHPWAMP默认集成VC,不需要单独安装) 那么什么是WAMP环境?WAMP这个词是什么意思? Windows ...

  4. 正则表达式之js检验密码强度

    最近一直在做通行证项目,里面的注册模块中输入密码需要显示密码强度(低中高).今天就把做的效果给大家分享下,代码没有网上搜索的那么复杂,能够满足一般的需求. html 代码如下: <!DOCTYP ...

  5. orm2

    数据库连接 var orm = require("orm"); orm.connect("mysql://username:password@host/database& ...

  6. MVC-Area

    ASP.NET MVC中,是依靠某些文件夹以及类的固定命名规则去组织model实体层,views视图层和控制层的.如果是大规模的应用程序,经常会由不同功能的模块组成,而每个功能模块都由MVC中的三层所 ...

  7. Winform_devexpress开发框架主界面设计

    做了好多年的C#开发,从.Net.Winform及第三方的DevExpress.无论什么样的系统,主界面的设计及风格无疑非常重要.从客户的角度考虑,要求功能区清晰,整体美观大方,这样才会有可能从第一视 ...

  8. mariadb 设置远程访问

    GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY '123456' WITH GRANT OPTION; flush privileges; ...

  9. 敏捷开发(六)- SCRUM全员会议

    本文主要是为了检测你对SCRUM 全员会议的了解和使用程度,通过本文你可以检测一下  1.你们的SCRUM 全员会议的过程和步骤    2.SCRUM 全员会议的输出结果 一.会议目的     组成团 ...

  10. JS---控制键盘事件

    键盘事件汇总: 1.onkeydown 键盘按下时触发; 2.onkeyup  键盘按下后抬起触发的事件  3.onkeypress 这个事件在用户按下并放开任何字母数字键时发生(不常用) keyCo ...