codeforces 703B Mishka and trip

4.图像sensor的特性和驱动解析 例子:sensor驱动自己提供操作曝光时间的函数和获取曝光时间的函数,然后将这个函数注册到ISP库和3A算法库,3A算法库根据外部光照强度计算出一个Sensor曝光时间的设置值,ISP库得到这个设置值,然后通过Sensor之前注册的回调函数,把这个值设置到Sensor的硬件寄存器中去,实现整个过程。是为 ISP 配置正确的输入时序。(1)修改驱动源码(sambashar\Hi3518E_SDK_V1.0.3.0\package\mpp\component\isp\sensor\ar0130) 阅读详情

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

Little Mishka is a great traveller and she visited many countries. After thinking about where to travel this time, she chose XXX — beautiful, but little-known northern country.

Here are some interesting facts about XXX:

  1. XXX consists of n cities, k of whose (just imagine!) are capital cities.
  2. All of cities in the country are beautiful, but each is beautiful in its own way. Beauty value of i-th city equals to ci.
  3. All the cities are consecutively connected by the roads, including 1-st and n-th city, forming a cyclic route 1 — 2 — ... — n — 1. Formally, for every 1 ≤ i < n there is a road between i-th and i + 1-th city, and another one between 1-st and n-th city.
  4. Each capital city is connected with each other city directly by the roads. Formally, if city x is a capital city, then for every1 ≤ i ≤ n,  i ≠ x, there is a road between cities x and i.
  5. There is at most one road between any two cities.
  6. Price of passing a road directly depends on beauty values of cities it connects. Thus if there is a road between cities i and j, price of passing it equals ci·cj.

Mishka started to gather her things for a trip, but didn't still decide which route to follow and thus she asked you to help her determine summary price of passing each of the roads in XXX. Formally, for every pair of cities a and b (a < b), such that there is a road betweena and b you are to find sum of products ca·cb. Will you help her?

Input

The first line of the input contains two integers n and k (3 ≤ n ≤ 100 000, 1 ≤ k ≤ n) — the number of cities in XXX and the number of capital cities among them.

The second line of the input contains n integers c1, c2, ..., cn (1 ≤ ci ≤ 10 000) — beauty values of the cities.

The third line of the input contains k distinct integers id1, id2, ..., idk (1 ≤ idi ≤ n) — indices of capital cities. Indices are given in ascending order.

Output

Print the only integer — summary price of passing each of the roads in XXX.

Examples
input
4 1
2 3 1 2
3
output
17
input
5 2
3 5 2 2 4
1 4
output
71
Note

This image describes first sample case:

It is easy to see that summary price is equal to 17.

This image describes second sample case:

It is easy to see that summary price is equal to 71.



#include <cstdio>
#include <iostream>
#include <algorithm>
#include <map>

using namespace std;

typedef long long ll;

ll n, k, a[100005], b[100005], sum, tsum, res;

int main()
{
	cin >> n >> k;
	sum = 0;
	for (ll i = 0; i < n; i++) {
		scanf("%I64d", &a[i]);
		sum += a[i];
	}
	for (ll i = 0; i < k; i++) {
		scanf("%I64d", &b[i]);
	}
	map<ll, ll> mp; //标记之前算过的首都,避免重复计算
	res = 0; tsum = 0;  //tsum用于去重
	//先算所有与首都相连的路
	for (ll i = 0; i < k; i++) {
		res = res + (sum - a[b[i] - 1] - tsum) * a[b[i] - 1];
		mp[b[i] - 1] = 1;
		tsum += a[b[i] - 1];
	}
	//算非首都之间的路
	a[n] = a[0];
	for (ll i = 1; i <= n; i++) {
		if (!mp[i % n]) {
			if (!mp[i - 1]) {
				res += a[i - 1] * a[i];
			}
		}
	}
	cout << res << endl;
	return 0;
}





利用PaddleOCR识别增值税发票平台验证码(开箱即用) 下面直接讲解利用paddleocr识别的思路,为什么使用paddleocr,因为paddle中集成了较好的ocr文字识别模型,开箱即用即可,废话不多说,剑指主题,识别思路步骤如下。 阅读详情

相关推荐

宇树G1双足机器人SLAM开发环境搭建实战指南

SLAM(同步定位与建图)是机器人自主导航的核心技术。在双足人形机器人平台上,由于运动模型复杂、机身晃动带来高频IMU噪声,SLAM开发对环境配置和依赖管理提出了更高要求。以宇树G1为例,系统阐述如何通过Ubuntu 20.04、ROS Noetic与Docker容器化方案构建可复现的SLAM开发环境。先介绍依赖分层管理与版本锁定原理,再深入catkin工作空间编译、传感器驱动集成、网络与多机通信配置等工程实践,最后提供常见问题排查与避坑指南。这套方法论不仅适用于G1,也可迁移至其他双足或轮式机器人平台,帮

weixin_32025789的博客 280

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

原题链接 B. Mishka and trip time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little Mishka is a great travel

L. 308

手把手教你用示波器实测CAN总线波形:快速区分高速、低速及常见故障

本文详细介绍了如何使用示波器实测CAN总线波形,快速区分高速CAN总线和低速CAN总线,并诊断常见故障。通过实战案例和波形分析,帮助工程师掌握CAN总线信号特征,提升故障排查效率,适用于汽车电子和工业控制领域。

weixin_33217202的博客 422

CodeForces 703B Mishka and trip【水题】

Mishka and trip time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little Mishka is a great traveller and ...

weixin_33909059的博客 214

豆包Agent实战指南:从智能体原理到办公自动化应用

智能体(Agent)作为人工智能领域的重要概念,其核心在于通过思考-行动-观察循环,实现从被动响应到主动执行的任务范式转变。这一原理使得AI能够理解用户意图、规划步骤并调用工具,从而完成复杂操作,其技术价值在于显著降低自动化门槛,让非技术用户也能构建定制化工作流。在应用场景上,智能体广泛应用于自动化办公、数据分析、信息整理等领域,通过自然语言交互简化重复性任务。本文以豆包Agent为例,深入探讨如何利用其工具调用和指令配置能力,例如创建文档整理助手,实现会议纪要的自动结构化与Markdown格式化,并解析其

weixin_33708633的博客 396

Seedance2.5本地部署指南:从环境配置到生产优化的完整实践

在 AI 内容生成领域,本地部署方案正逐渐成为开发者和技术团队关注的焦点。Seedance2.5 作为一款支持图像和视频生成的 AI 工具,其完全离线运行的能力解决了云端服务在数据隐私、使用成本和访问稳定性方面的痛点。对于需要处理敏感内容、频繁生成素材或希望完全掌控生成流程的技术人员来说,掌握本地部署方法具有实际价值。 本文将以 Seedance2.5 的本地部署为例,详细介绍从环境准备、依赖配置到运行验证的完整流程,同时深入分析关键参数配置、常见问题排查方法以及生产环境下的优化建议。通过实际部署过程,理解

weixin_33139275的博客 815

codeforces - 703B - Mishka and trip(数学)

LINK:http://codeforces.com/contest/703/problem/B 题意:一个国家有n个城市,其中里面有k个省会,每个城市有点权。每个城市都和它前一个城市和后一个城市有边,第n个城市还有一条到第一个城市的边,省会到每个城市都有边。对每条边u-v边权都是c[u]*c[v]。求全部边圈和。 解法:n*n会t,给给。sum是首府的权值和。对每个不是首府的点,它到所有首府的

horihori_的博客 451

Allegro如何输出ODB文件操作指导

在PCB设计完成之后,需要输出生产文件用于生产加工,除了gerber文件可以用生产制造,ODB文件同样也可以用于生产,如下图。用Allegro如何输出ODB文件,具体操作如下。如何输出ODB文件操作指导。

weixin_54787054的博客 7253

CodeForces 703B

D - Mishka and trip Little Mishka is a great traveller and she visited many countries. After thinking about where to travel this time, she chose XXX — beautiful, but little-known northern country. Her...

给我一把键盘 218

米哈游运维面试题及参考答案

Linux 系统运行级别是用于定义系统启动时所需要达到的功能状态。运行级别 0:表示系统停机状态,用于关闭系统,是系统的关机级别。当系统切换到这个级别时,会停止所有的服务和进程,然后关闭系统。运行级别 1:也称为单用户模式。在这个级别下,系统只启动基本的系统服务和必要的进程,仅允许 root 用户登录系统进行维护操作,常用于系统出现故障需要紧急修复的情况,比如修复文件系统错误、重置 root 密码等。运行级别 2:多用户模式,但不支持网络文件系统(NFS)。

大模型大数据攻城狮的专栏 753

【Go语言实战】(26) 分布式搜索引擎

基于go语言的分布式搜索引擎

面向生活编程 2391

还以为是个贪心(智商不够)(控制 i j循环)

B - BTime Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d &amp; %I64uSubmit Status Practice CodeForces 961B use MathJax to parse formulasDescription你的朋友Mishka和你参加一个微积分讲座。讲座持续n分钟。讲师在第i...

najiuzheyangbaacm的博客 272

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

【打CF,学算法——二星级】Codeforces 703B Mishka and trip (统计)

【CF简介】 题目链接:CF 703B 题面: A - Mishka and trip Time Limit:1000MS    Memory Limit:262144KB    64bit IO Format:%I64d & %I64u SubmitStatusPracticeCodeForces 703B Description L

David_Jett 1391

vb 6.0并口开发操作实例

vb6并口开发,简体中文,试例内有inpout32.dll动态链接库

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

Mishka and trip CodeForces - 703B

Mishka and trip Little Mishka is a great traveller and she visited many countries. After thinking about where to travel this time, she chose XXX — beautiful, but little-known northern country. Here ar...

weixin_43895356的博客 274

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

Codeforces 703B Mishka and trip

703B Mishka and trip 给n个点 围成一个环 相邻节点有边 给你k个点 这k点与另外所有点右边 问 对于所有边 edge[i][j] 求Σedge[i][j].val edge[i]j[j].val==val[i]*val[j]; 解决: 1.先求环上的边 2.对于 对于每个特殊的点 顺次求出他对这张图的贡献 (要对a[0]和a...

fnq9999的博客 206

Codeforces 703B. Mishka and trip

题目链接:http://codeforces.com/problemset/problem/703/B 题意:   在一个国家有 N 个城市,编号为 1 ~ N, 每个城市有一个漂亮值 Ci.每两个相邻编号的城市之间都有一条路,也就是说第 i 个城市和第 i + 1 个城市之间有一条路,特别的第一个城市和最后一个城市之间有一条路,路的价值为路两端城市的漂亮值的积,即 Ci * Ci+...

dimaishu7553的博客 155

CodeForces 703B Mishka and trip

http://codeforces.com/problemset/problem/703/B #include<stdio.h> #include<string> #include<cstring> #include<queue> #include<algorithm> #include<functional> #include<vector> #include<iomanip> #include<

Katapeltes 342

Codeforces-703B Mishka and trip

题目大意: 给你n个点,标号为1-n,并且相邻的两个点之间存在路径,其路径权值为路径两端点权值的乘积,现在在1-n中有k个点,这k个点对其它任意一点都需要存在路径,但是两个点之间的路径不能超过一条。也就是没有重边,现在问你整个图的路径权值之和是多少 解题思路: 因为这题的数据为10w所以不可能用两两之间路径来枚举,那么有个简单的思路就是只需要知道与i点相连的路径权值之和就可以了。 而对于k

Wilbert的博客 629

Codeforces703B Mishka and trip

题意: 就是有n个点,本来相邻点之间就有一条边,1和n之间也有一条,然后给你几个特殊点,说这些特殊点和其他所有点都连起来了,然后算一个所有边的权值和,每条边的权值等于两个点的c相乘。 思路: 水题啊…感觉有好多方法吧。弱的思路:你把所有点都相连的情况,把所有边权值和算出来,然后没有被标记的点拿出来,把他们两两相连的边的权值也减掉,但是你会发现就算没有标记但是相邻还是会有边,所以加上这些就好了。

ONE MORE TRY 739

CodeForces703B Mishka and trip 数学

Little Mishka is a great traveller and she visited many countries. After thinking about where to travel this time, she chose XXX — beautiful, but little-known northern country. Here are some intere

Megumin的博客 514

codeforces 703B. Mishka and trip

B. Mishka and trip time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little Mishka is a great traveller and sh

R 416

(模拟+数学)codeforces - 703B Mishka and trip

原题链接: http://codeforces.com/problemset/problem/703/B 题意: 有n个城市,1-n形成一个环,其中有k个省会,每个省会应该和每个城市都连起来。每个城市有一个美丽值,两城市之间的连路的美丽值为两城市美丽值的乘积,要求所有连路的美丽值的总和。 分析: 首先想到的是先把所有情况加起来,再减去会重复的。但是写起来比较麻烦而且...

dijieluan7764的博客 165

【Codeforces 703B - Mishka and trip】

B. Mishka and trip time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Little Mishka is a great traveller and she visited many countries. After

楚江枫 462
上一篇: hdu5778 abs 素数筛法 暴力枚举
下一篇: codeforces 151C Win or Freeze
Daemoonn
博客等级 码龄11年 42粉丝 198原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址