CodeForces 703B Mishka and trip
简单题。
先把环上的贡献都计算好。然后再计算每一个$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的更多相关文章
- Codeforces 703B. Mishka and trip 模拟
B. Mishka and trip time limit per test:1 second memory limit per test:256 megabytes input:standard i ...
- CodeForces 703A Mishka and trip
Description Little Mishka is a great traveller and she visited many countries. After thinking about ...
- codeforces 703B B. Mishka and trip(数学)
题目链接: B. Mishka and trip time limit per test 1 second memory limit per test 256 megabytes input stan ...
- Codeforces Round #365 (Div. 2) Mishka and trip
Mishka and trip 题意: 有n个城市,第i个城市与第i+1个城市相连,他们边的权值等于i的美丽度*i+1的美丽度,有k个首都城市,一个首都城市与每个城市都相连,求所有边的权值. 题解: ...
- cf703B Mishka and trip
B. Mishka and trip time limit per test 1 second memory limit per test 256 megabytes input standard ...
- 暑假练习赛 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 ...
- codeforces 703E Mishka and Divisors
codeforces 703E Mishka and Divisors 题面 给出大小为\(1000\)的数组和一个数\(k\),求长度最短的一个子序列使得子序列的元素之积是\(k\)的倍数,如果有多 ...
- Codeforces 703D Mishka and Interesting sum 离线+树状数组
链接 Codeforces 703D Mishka and Interesting sum 题意 求区间内数字出现次数为偶数的数的异或和 思路 区间内直接异或的话得到的是出现次数为奇数的异或和,要得到 ...
- Codeforces 703B (模拟) Mishka and trip
题目:这里 题意:n个城市,每个城市有个魅力值vi,首先,有n条路将这n个城市连成一个环,1号城市连2号城市,2号连3号****n号连1号城市,每条路的魅力值是其连接的两个城市 的魅力值的乘积,这n个 ...
随机推荐
- Golang爬虫示例包系列教程(一):pedaily.com投资界爬虫
Golang爬虫示例包 文件结构 自己用Golang原生包封装了一个爬虫库,源码见go get -u -v github.com/hunterhug/go_tool/spider ---- data ...
- 舒适的路线 (code[vs] 1001)
传送门 :code[vs] 1001 思路:拿到这题的首先的思路 , 就是跑一遍最短路. 可是在尝试了一会后发现不会写,于是果断弃 尝试另外的算法.. 于是就有的以下的算法.并查集 + 乱搞(有点像 ...
- 前端——HTML笔记Two
web前端需要掌握:HTML.CSS.JavaScript语言.这三门技术用来实现: 1. HTML是网页内容的载体.内容就是网页制作者放在页面上想要让用户浏览的信息,可以包含文字.图片.视频等. 2 ...
- 初识git--基础命令
重要:远程分支是一些无法移动的本地分支,本地分支,本地分支,三遍!是对远程库中分支的索引,只有在git进行网络交互时才会更新,用 (远程仓库名)/(分支名) 这样的形式表示远程分支 一.基础命令1 1 ...
- python json数组对象排序
arr = [{"name": "name_1", "level": 1}, {"name": "name_2 ...
- 常见的 http 状态码
1~5开头的HTTP状态码分别表示: 1XX 表示消息 2XX 表示成功 3XX 表示重定向 4XX 表示请求错误 5XX 表示服务端错误 常见的HTTP状态码: 200 OK 表示请求成功 一切正常 ...
- DuiLib 中滚动条不显示的问题
DuiLib 很好用,同时在没有完全理解源码的前提下,坑也不少,比如今天遇到的添加滚动条不显示... 情况是这样的,将一个页面作为Tab控件的其中一页,为了代码不窝在一起,就没有在CreateCont ...
- centos7下引导win7
1.使用root身份(必须)打开 /boot/grub2/grub.cfg 2.找到 ### BEGIN /etc/grub.d/30_os-prober ### 在后面添加 menuentry &q ...
- 转:Spark User Defined Aggregate Function (UDAF) using Java
Sometimes the aggregate functions provided by Spark are not adequate, so Spark has a provision of ac ...
- Linux中一些简单命令(一)
1.查看当前用户:who 2.显示当前目录:pwd 3.查看当前服务器的时间:date 4.查看日历:cal+year; 例如:cal 2016 5.计算器:bc 退出计算器:quit或者ctrl+ ...