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 ...
随机推荐
- Go 跟踪函数调用链,理解代码更直观
Go 跟踪函数调用链,理解代码更直观 目录 Go 跟踪函数调用链,理解代码更直观 一.引入 二.自动获取所跟踪函数的函数名 三.增加 Goroutine 标识 四.让输出的跟踪信息更具层次感 五.利用 ...
- RocketMQ—引言
RocketMQ-引言 MQ介绍 在学习RocketMQ之前,我们先来看以下MQ的意思. MQ是Message Queue的首字母缩写. Message:意思为消息,在我们生活中可以是一句话/一个短信 ...
- 关于Curl命令的使用
最常用的curl命令 1.发送GET请求 curl URL 例: curl URL?a=1&b=nihao 2.发送POST请求 curl -X POST -d 'a=1&b=niha ...
- TienChin-课程管理-添加课程页面
course.js 将 activity 替换成 course. index.vue 这个 index.vue 是 course 文件夹下面的 index.vue 别弄错了. <template ...
- 解决: DECODER_ERROR_CLASSES += (brotli.error,) ttributeError: module ‘brotli‘ has no attribute ‘error‘
解决: DECODER_ERROR_CLASSES += (brotli.error,) ttributeError: module 'brotli' has no attribute 'error' ...
- Pdfium.Net.Free 一个免费的Pdfium的 .net包装器--PDF预览器框选
项目地址: Pdfium.Net:https://github.com/1000374/Pdfium.Net PdfiumViewer:https://github.com/1000374/Pdfiu ...
- maven打包报错
* 系统:macOS* 开发工具:Idea* 问题描述:在idea中执行mvn clean install时报No compiler is provided in this environment. ...
- 予力八六三软件应用现代化,提升DevSecOps效能,探索交付之路
本文分享自华为云社区<予力八六三软件应用现代化,提升DevSecOps效能,探索全球交付之路>,作者: HuaweiCloudDeveloper. 来源:<华为云DTSE>期刊 ...
- MutationObserver对象
MutationObserver对象 MutationObserver (W3C DOM4)对象提供了监视对DOM树所做更改的能力,其被设计为旧的Mutation Events功能的替代品(该功能是D ...
- C++ 时间复杂度
看到网上一些资料的案例不全,所以自己开个来复习. O(1)<O(log2n)<O(n)<O(nlog2n)<O(n^2)<O(n^3)<-<O(2^n)< ...