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个 ...
随机推荐
- NUTZ中处理系统未捕获异常
关键内容 mvc-chain.js ViewProcessor ai.setFailView(“redirect:/sysError.html”); log.error(this.trrowableT ...
- PHP之MYSQL数据库
MYSQL数据库简介 1.什么是数据库? 数据库(database) 就是一个由一批数据构成的有序集合,这个集合通常被保存为一个或多个彼此相关的文件. 2.什么是关系型数据库? 数据被分门别类的存 ...
- 《DSP using MATLAB》示例Example6.4
图形表达如下: 代码: b = [1, 0, 0, 0, 16+1/16, 0, 0, 0, 1]; [b0, B, A] = dir2cas(b, 1) 运行结果: 写成公式为
- oracle数据库连接串格式
oracle常用链接串格式:jdbc:oracle:thin:@//<host>:<port>/<service_name> jdbc:oracle:thin:@& ...
- mac nodejs安装
很久没有配置开发环境了,刚换了新电脑,正好借机会重新配置一下node相关的开发环境 安装 nvm :Node Version Manager 由于nodejs版本更新迭代较快,而不同版本间的差异又很大 ...
- 如何得到AdoConnection.execute(sqlstr)执行的返回结果
如何得到AdoConnection.execute(sqlstr)执行的返回结果? 1: TAdoConnection.execute有procedure.function的两种定义,function ...
- android studio 将library导出为jar 亲测成功
本人使用的是helloChart这个开源项目,其主要用于图表,来自git 地址为:https://github.com/lecho/hellocharts-android 下载命令为 git clon ...
- android 界面布局
一.LinearLayout LinearLayout 又称作线性布局,是一种非常常用的布局,它所包含的控件在线性方向上依次排列. android:orientation="horizont ...
- NGINX----源码阅读---cycle
/* * Copyright (C) Igor Sysoev * Copyright (C) Nginx, Inc. */ #ifndef _NGX_CYCLE_H_INCLUDED_#define ...
- http&https&证书&数字签名
http协议 http是超文本传输协议,是用来网络间传输数据.底层是tcp协议(传输控制协议). 是一种面向连接的主机对主机层的可靠传输,这里的可靠是指数据丢失极小.Tcp建立一次连接需要经过3次握手 ...