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 ...
随机推荐
- ABP-VNext 用户权限管理系统实战----问题与解决方案
1.swagger请求总是报:400 Bad Request,但是postman请求是没有问题 查看日志报表: 解决方案: 在 ConfigureServices 中增加如下的内容 Configure ...
- Go语言的100个错误使用场景(一)|代码和项目组织
目录 前言 1. Go: Simple to learn but hard to master 1.1 Go 语言概述 1.2 简单不等于容易 1.3 使用 Go 的100个错误 2. Code an ...
- 【二】MADDPG多智能体算法实现(parl)【追逐游戏复现】
相关文章: [一]MADDPG-单智能体|多智能体总结(理论.算法) [二]MADDPG多智能体深度强化学习算法算法实现(parl)--[追逐游戏复现] 程序链接:直接fork:MADDPG多智能体深 ...
- Pdfium.Net.Free 一个免费的Pdfium的 .net包装器--打开大文件处理
项目地址: Pdfium.Net:https://github.com/1000374/Pdfium.Net PdfiumViewer:https://github.com/1000374/Pdfiu ...
- 46从零开始用Rust编写nginx,数据还能这么传,多层代理(IP多级代理)搭建
wmproxy wmproxy已用Rust实现http/https代理, socks5代理, 反向代理, 负载均衡, 静态文件服务器,websocket代理,四层TCP/UDP转发,内网穿透等,会将实 ...
- Redis安装及使用详解篇
一.什么是Redis? Redis(Remote Dictionary Server ),即远程字典服务. Redis是是现在最受欢迎的NoSQL数据库之一,是一种支持key-value等多种数据结构 ...
- Java并发(八)----使用线程避免cpu占用100%
1.sleep 实现 在没有利用 cpu 来计算时,不要让 while(true) 空转浪费 cpu,这时可以使用 yield 或 sleep 来让出 cpu 的使用权给其他程序 while(true ...
- 小知识:grep过滤以#号开头的注释行 和 空行
xtts的配置文件,有很多注释不想直接去掉的情况下,想清楚的看到目前设置了哪些参数,可以用grep过滤查看: grep -vE '^#|^$' xtt.properties 效果如下: [oracle ...
- Docker生命周期,一张图秒懂docker
- MySQL8 查询优化新工具 Explain Analyze
1.什么是Explain Analyze? Explain 是我们常用的查询分析工具,可以对查询语句的执行方式进行评估(并非实际的执行情况,可能与实际情况存在较大差距),给出很多有用的线索. Expl ...