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 ...
随机推荐
- TienChin 渠道管理-字典原理分析
在上一节当中,我们使用到了字典来进行翻译我们的渠道类型等等字段,那么这一节我们就来分析一下字典的原理. 从代码方面先开始分析,我们先来看一下字典的定义,我们是在如下图当中编写了我们的渠道类型,使用,p ...
- 3.6 Windows驱动开发:内核进程汇编与反汇编
在笔者上一篇文章<内核MDL读写进程内存>简单介绍了如何通过MDL映射的方式实现进程读写操作,本章将通过如上案例实现远程进程反汇编功能,此类功能也是ARK工具中最常见的功能之一,通常此类功 ...
- C/C++ 简单特征码匹配
特征码定位查杀 简单提取一段特征码字段. 代码编写. #include <stdio.h> #include <Windows.h> #define FileLEN 20 // ...
- 《Spring 手撸专栏》| 开篇介绍,我要带新人撸 Spring 啦!
作者:小傅哥 博客:https://bugstack.cn 沉淀.分享.成长,让自己和他人都能有所收获! 一.前言 不正经!写写面经,去撸Spring源码啦? 是的,在写了4篇关于Spring核心源码 ...
- SpringSecurity使用步骤
一.导入jar包(使用maven构建项目导入其坐标) <dependency> <groupId>org.springframework.security</groupI ...
- 月薪40K+的测试老兵,测试开发学习实战心得分享
1. 前言 大家好,我是Arthur,拥有超过10年以上的银行测试经验,目前在一家互联网创业公司担任测试经理.在我们那个年代,基本上都是不会写代码的做测试工作,而且基本都是纯手工:最近几年,测试开发开 ...
- Mac 和 windows上 好用的截图 工具 Snipaste
Snipaste 官网:https://zh.snipaste.com/ ========================= 使用方法,比较简单,可以官网查看
- Hadoop-基础知识面试题
1.Hadoop集群的最主要瓶颈 磁盘IO 2.Hadoop三大组件 (1).HDFS HDFS(Hadoop Distributed File System)是 Hadoop 项目的核心子项目,主要 ...
- 【OpenGL ES】纹理贴图
1 前言 纹理贴图是指:将图片贴在模型的表面. 纹理贴图的本质是:将图片划分为一系列三角形,使得图片顶点序列与模型顶点序列中的顶点一一对应,对于模型中任意三角形内部的坐标和图片中对应三角形内部 ...
- WinRT: 可能是 Windows 上最好用的 Native ABI 和远程调用方案
前言 Windows 自从很久以来就有一个叫做 COM 的 Native ABI.这是一套面向对象的 ABI,在此之上 Windows 基于 COM ABI 暴露了各种各样的 API,例如 Manag ...