11 .Codeforces Round 891 (Div. 3)E. Power of Points(推公式+前缀和优化)
E. Power of Points

题解参考
#include <bits/stdc++.h>
#define int long long
#define rep(i, a, b) for(int i = (a); i <= (b); ++i)
#define fep(i, a, b) for(int i = (a); i >= (b); --i)
#define _for(i, a, b) for(int i=(a); i<(b); ++i)
#define pii pair<int, int>
#define pdd pair<double,double>
#define ll long long
#define db double
#define x first
#define y second
#define pb push_back
#define vi vector<int>
using namespace std;
const int maxn = 1e5 + 10;
//int l[maxn],r[maxn],n;
struct node {
int val, pos;
bool operator<(const node &t) const {
return val < t.val;
}
};
void solve() {
int n;
cin >> n;
vector<node> a(n + 1);
vi l(n + 1), r(n + 2);
rep(i, 1, n) {
int k;
cin >> k;
a[i] = {k, i};
}
sort(a.begin() + 1, a.end());
//预处理前缀和、后缀和
rep(i, 1, n) {
l[i] = l[i - 1] + a[i].val;
}
r[n] = a[n].val;
fep(i, n - 1, 1) {
r[i] = r[i + 1] + a[i].val;
}
vi ans(n + 1);
rep(i, 1, n) {
int res = n + (2 * i - n) * a[i].val - l[i] + r[i + 1];
ans[a[i].pos] = res;
}
rep(i, 1, n) {
cout << ans[i] << ' ';
}
cout << endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// freopen("C:\\Users\\24283\\CLionProjects\\untitled2\\1.in", "r", stdin);
int _;
cin >> _;
while (_--)
solve();
return 0;
}
总结
- 注意下标
11 .Codeforces Round 891 (Div. 3)E. Power of Points(推公式+前缀和优化)的更多相关文章
- Codeforces Round #133 (Div. 2), A.【据图推公式】 B.【思维+简单dfs】
Problem - 216A - Codeforces Problem - B - Codeforces A Tiling with Hexagons 题意: 给出a b c ,求里面有多少个六边形 ...
- Codeforces Round #596 (Div. 2)D.Power Products
题意: 给一个数组,给你一个k,找出两个数字的积可以变成xk的数对对数 解析: 当且仅当,两个数进行质因子分解后每个因子的个数都是k的倍数个就说明这是满足条件的一对,可以让每个因子个数%k用map找对 ...
- [每日一题2020.06.11]Codeforces Round #644 (Div. 3) H
A-E见 : 这里 题目 我觉得很有必要把H拿出来单独发( 其实是今天懒得写题了 ) problem H 一个从 1 到 $ 2^m - 1$ 的长度为m的连续二进制序列, 删去指定的n个数, 问剩余 ...
- Codeforces Round #666 (Div. 2) B. Power Sequence (枚举)
题意:有一个长度为\(n\)的序列,你每次可以对序列重新排序,然后花费\(1\)使某个元素加减\(1\),多次操作后使得新序列满足\(a_{i}=c^i\),\(c\)是某个正整数,求最小花费. 题解 ...
- Codeforces Round #333 (Div. 1) C. Kleofáš and the n-thlon 树状数组优化dp
C. Kleofáš and the n-thlon Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...
- Codeforces Round #331 (Div. 2)C. Wilbur and Points 贪心
C. Wilbur and Points Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/596/ ...
- Codeforces Round #248 (Div. 1) B. Nanami's Digital Board 暴力 前缀和
B. Nanami's Digital Board 题目连接: http://www.codeforces.com/contest/434/problem/B Description Nanami i ...
- Codeforces Round #419 (Div. 2) B. Karen and Coffee(经典前缀和)
http://codeforces.com/contest/816/problem/B To stay woke and attentive during classes, Karen needs s ...
- Codeforces Round #331 (Div. 2) C. Wilbur and Points
C. Wilbur and Points time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- Codeforces Round #219 (Div. 2) D. Counting Rectangles is Fun 四维前缀和
D. Counting Rectangles is Fun time limit per test 4 seconds memory limit per test 256 megabytes inpu ...
随机推荐
- 最新 Hugging Face 强化学习课程(中文版)来啦!
人工智能中最引人入胜的话题莫过于深度强化学习 (Deep Reinforcement Learning) 了,我们在 2022 年 12 月 5 日开启了<深度强化学习课程 v2.0>的课 ...
- C# 输入指定日期获取当前年的第一天 、当前年的最后天、某月的第一天 、某月的最后一天
方法 /// <summary> /// 取得当前年的第一天 /// </summary> /// <param name="datetime"> ...
- 从零开始配置vim(31)——git 配置
很抱歉又拖更了这么久了,在这个新公司我想快速度过试用期,所以大部分的精力主要花在日常工作上面.但是这个系列还是得更新下去,平时只能抽有限的业余时间来准备.这就导致我写这些文章就慢了一些. 废话不多说, ...
- 物联网浏览器(IoTBrowser)-电子秤模块及二次驱动开发
本章介绍电子秤模块的示例功能以及二次开发称重驱动的代码,二次开发以顶尖OS2型号驱动为示例,实现方式与物联网浏览器(IoTBrowser)-顶尖OS2电子秤协议实现类似,不同的是电子秤只需要采集重量不 ...
- 第二届数字化经济与管理科学国际学术会议(CDEMS 2024)
[经济&管理|录用率高]第二届数字化经济与管理科学国际学术会议(CDEMS 2024) 2024 2nd International Conference on Digital Economy ...
- 遥感图像处理笔记之【Machine Learning CS-433 - Class Project 2 - Road Segmentation - EPFL】
遥感图像处理学习(8) 前言 遥感系列第8篇.遥感图像处理方向的学习者可以参考或者复刻 本文初编辑于2024年1月2日 本文再编辑于2024年1月4日:附作者改进U-Net网络图片:文字补充说明 20 ...
- Java开发学习(四十七)----MyBatisPlus删除语句之多记录操作
1.多记录操作 先来看下问题: 之前添加了很多商品到购物车,过了几天发现这些东西又不想要了,该怎么办呢? 很简单删除掉,但是一个个删除的话还是比较慢和费事的,所以一般会给用户一个批量操作,也就是前面有 ...
- Java微服务SpringCloud+Uniapp+Vue3+Element Plus开源BizSpring商城
产品介绍 BizSpring电商平台概述 BizSpring电商平台,是基于最新Spring Cloud 微服务架构开发的多语言电商平台,使用领先的 Vue3.0+ElementPlus + unia ...
- 剑指Offer07 重建二叉树
剑指 Offer 07. 重建二叉树 前置概念: 前序:访问根节点,先序遍历左子树,先序遍历右子树: 中序:中序遍历左子树,访问根节点,中序遍历右子树: 后序:后序遍历左子树,后序遍历右子树,访问根节 ...
- Teams基础功能与会议介绍
目录 Teams基本功能介绍 活动 聊天 如何查找联系人 如何开启语音或视频通话 如何共享自己的屏幕 如何新建群聊 发送文件的多种方式 快速安排一个会议 重要与紧急的消息 文件 分享的文件 OneDr ...