当前位置:网站首页>[training day15] simple calculation [tree array] [mathematics]
[training day15] simple calculation [tree array] [mathematics]
2022-07-25 22:31:00 【VL——MOESR】

Ideas :
We can count the same , Then subtract it
c o d e code code
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
const long long MAXN = 1e5 + 10;
long long n;
long long a[MAXN], l[MAXN], r[MAXN], l1[MAXN], r1[MAXN];
long long cl[MAXN], cr[MAXN];
long long tot, k[MAXN];
long long lowbit(long long x) {
return x & -x; }
void add_l(long long x) {
for(; x <= MAXN - 10; x += lowbit(x)) cl[x] ++;
}
long long query_l(long long x) {
long long ans = 0;
for(; x; x -= lowbit(x)) ans += cl[x];
return ans;
}
void add_r(long long x) {
for(; x <= MAXN - 10; x += lowbit(x)) cr[x] ++;
}
long long query_r(long long x) {
long long ans = 0;
for(; x; x -= lowbit(x)) ans += cr[x];
return ans;
}
int main() {
freopen("a.in", "r", stdin);
freopen("a.out", "w", stdout);
scanf("%lld", &n);
for(long long i = 1; i <= n; i ++) scanf("%lld", &a[i]), k[i] = a[i];
sort(k + 1, k + 1 + n);
int tot = unique(k + 1, k + 1 + n) - k - 1;
for(long long i = 1; i <= n; i ++) a[i] = lower_bound(k + 1, k + 1 + tot, a[i]) - k;
long long s1 = 0, s2 = 0;
for(long long i = 1; i <= n; i ++) {
add_l(a[i]);
s1 += query_l(a[i] - 1);
l[i] = query_l(a[i] - 1);
l1[i] = query_l(MAXN) - query_l(a[i]);
}
for(long long i = n; i >= 1; i --) {
add_r(a[i]);
s2 += query_r(a[i] - 1);
r[i] = query_r(MAXN) - query_r(a[i]);
r1[i] = query_r(a[i] - 1);
}
long long s3 = 0;
for(long long i = 1; i <= n; i ++) s3 += l[i] * r1[i] + r[i] * l1[i] + l1[i] * l[i] + r[i] * r1[i];
printf("%lld", s1 * s2 - s3);
return 0;
}
/* a b c d 1 4 4 3 1 4 4 2 1 3 3 2 */
/* 1 4 1 3 1 2 3 2 4 2 4 3 */
边栏推荐
- Data quality: the core of data governance
- What is the difference between character constants and string constants?
- 【集训DAY13】Travel【暴力】【动态规划】
- Mitsubishi FX PLC free port RS command realizes Modbus Communication
- Scratch seamless butt bron filter
- xss-工具-Beef-Xss安装以及使用
- D3.js 学习
- Short circuit effect of logical operators short circuit and short circuit or
- 分享两个音乐播放地址
- 编译器引论
猜你喜欢

QML module not found

Interpretation of the source code of all logging systems in XXL job (line by line source code interpretation)

IPv4 addresses have been completely exhausted, and the Internet can work normally. NAT is the greatest contributor!

Win10 set up a flutter environment to step on the pit diary

3dslicer importing medical image data

Usage of in in SQL DQL query

Pyspark data analysis basis: pyspark.sql.sparksession class method explanation and operation + code display

关于getchar和scanf的使用示例及注意点

(1) Integrating two mapping frameworks of Dao

Randomly generate 10 (range 1~100) integers, save them to the array, and print the array in reverse order. And find the average value, the maximum value and the subscript of the maximum value, and fin
随机推荐
Based on if nesting and function call
【集训DAY15】油漆道路【最小生成树】
完啦,上班三个月,变秃了
【集训DAY13】Backpack【动态规划】【贪心】
Today, learn about the use of lists, hyperlinks, image tags, and audio and video
【集训DAY12】Minn ratio 【dfs】【最小生成树】
Wechat applet (anti shake, throttling), which solves the problem that users keep pulling down refresh requests or clicking buttons to submit information; Get the list information and refresh the data
JS interview questions
Short circuit and &, short circuit or |, logic and &, logic or |; Conditional operator
ORM common requirements
JVM内存区域
Compile and decompile
【集训DAY15】简单计算【树状数组】【数学】
Formal parameters, arguments and return values in functions
Learning orientation today
LabVIEW 开发 PCI-1680U双端口CAN卡
(1) DDL, DML, DQL, DCL and common data types
力扣解法汇总919-完全二叉树插入器
分割金条的代价
字符型常量和字符串常量的区别?