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个 ...
随机推荐
- zabbix 布署实践【7 H3C网络设备监控模版制作思路】
我们知道,zabbix安装后自带Template OS Linux 模版已满足了绝大部分Linux服务器的基础环境监控,只是我们在其模版上稍微修改,可配合将SWAP监控取消,另存为一个叫OS Linu ...
- Windows 8 卡在正在检查更新
原文地址:https://answers.microsoft.com/en-us/windows/forum/windows_8-update/windows-update-not-updating- ...
- jemeter逻辑控制器
1.ForEach控制器 ForEach控制器在用户自定义变量中读取一系列相关的变量.该控制器下的采样器或控制器都会被执行一次或多次,每次读取不同的变量值.所以ForEach总是和User Defin ...
- 同盾安卓 Android应用 集成步骤:
Android SDK 新版 Android SDK 旧版 1.点击下载最新SDK(当前版本3.0.3),并解压fraudmetrix-xxx.zip文件.解压后文件目录为: fm-core-xxx ...
- jq屏蔽f5
//屏蔽F5 $(document).ready(function () { $(document).bind("keydown", function (e) { e = wind ...
- html+css基础篇
2016年11月19号,计划把基础在看一下,听大神说好的东西就要多看几遍,知识是学来用的解决问题的,加油 接下来的是我在自学中的小笔记吧,每天都在保持几个小时的学习思考状态,由于要升本所以学前端的时间 ...
- ele.me在IOS浏览器端启动APP的技巧分析
ele.me在IOS浏览器端启动APP的技巧分析 巧妙利用后台重定向,在schemes启动时提示用户打开,启动不了APP时能够及时跳转至下载页面. 避免报错页面的出现以及用户还没来的及选择就跳转到下载 ...
- pyhon的数据类型
1.数字 整型和浮点型 在32位机器上,整数的位数为32位,取值范围为-2**31-2**31-1,即-2147483648-2147483647在64位系统上,整数的位数为64位,取值范围为-2** ...
- 用Redis作为Mysql数据库的缓存【转】
用Redis作Mysql数据库缓存,必须解决2个问题.首先,应该确定用何种数据结构存储来自Mysql的数据:在确定数据结构之后,还要考虑用什么标识作为该数据结构的键. 直观上看,Mysql中的数据都是 ...
- 如何使用Git上传代码到GitHub
1.在Github上面创建Github仓库: 2.下载Github Shell到本地:https://desktop.github.com/ 3.打开Github Shell,输入以下命令生成秘钥来验 ...