【逆序对】【线段树】【树状数组】Data Structure Special Training 1 T1 rotinv 题解
来源:互联网 发布:淘宝关键词热度 编辑:程序博客网 时间:2024/06/06 15:39
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <set>#include <queue>#include <algorithm>#include <vector>#include <cstdlib>#include <cmath>#include <ctime>#include <stack>#define INF 2100000000#define LL long long#define clr(x) memset(x,0,sizeof(x))#define ms(a,x) memset(x,a,sizeof(x))#ifdef win32#define AUTO "%I64d"#else#define AUTO "%lld"#endifusing namespace std;const int maxx = 1000005;int n,c[maxx],a[maxx];template <class T> inline void read(T &x) { int flag = 1; x = 0; char ch = getchar(); while(ch < '0' || ch > '9') { if(ch == '-') flag = -1; ch = getchar(); } while(ch >= '0' && ch <= '9') { x = (x<<1)+(x<<3)+ch-'0'; ch = getchar(); } x *= flag;}inline int lowbit(int x) { return x & (-x); }inline void add( int x ) { for(register int i = x; i <= n; i += lowbit(i)) c[i] += 1; }inline int query(int x) { int ans = 0; for(register int i = x; i; i -= lowbit(i)) ans += c[i]; return ans;}int main() { freopen("rotinv.in","r",stdin); freopen("rotinv.out","w",stdout); scanf("%d",&n); LL ans = 0, cnt = 0; for(register int i = 1; i <= n; i++) { scanf("%d",&a[i]); add(a[i]); cnt += i-query(a[i]); } for(register int i = 1; i <= n; i++) { cnt += (n-query(a[i]))-query(a[i]-1); ans += cnt; } cout << ans << endl; return 0;}
0 0
- 【逆序对】【线段树】【树状数组】Data Structure Special Training 1 T1 rotinv 题解
- 【线段树】Data Structure Special Training 1 T2 Rise 题解
- 【线段树】【数据结构】Data Structure Special Training 2 T1 setmod 题解
- 【主席树】【线段树】Data Structure Special Training 2 T3 intkth 题解
- 【扫描线】【线段树】Data Structure Special Training 2 T2 area 题解
- 【有序链剖】Data Structure Special Training 1 T3 seqmod 题解
- HDU 4217 Data Structure? 线段树 OR 树状数组
- 【树状数组+线段树动态开点】BZOJ3295(Cqoi2011)[动态逆序对]题解
- 2016 UESTC Training for Data Structures R - Japan CDOJ 383 树状数组 逆序对
- 【Data Structure】树状数组
- bzoj3295: [Cqoi2011]动态逆序对 树状数组套线段树
- 线段树 or 树状数组求逆序对
- 【BZOJ】3295 [Cqoi2011]动态逆序对 树状数组+线段树
- bzoj3295 动态逆序对【树状数组套权值线段树】
- 【CRT】【组合数】Number Theory Special Training T1 eqution 题解
- HDU 4217 Data Structure?(线段树 or 树状数组啊)
- 逆序对-树状数组-1
- 2016 UESTC Training for Data Structures E - 卿学姐与城堡的墙 树状数组求逆序对、离散化
- avro安装及编译测试文件
- Linux下安装Mysql
- 设计一个通用的帧栋画库
- mysql的关于TABLE_SCHEMA的sql语句和nformation_schema表
- Linux内核配置以及Make menuconfig过程分析
- 【逆序对】【线段树】【树状数组】Data Structure Special Training 1 T1 rotinv 题解
- 子元素垂直、左右居中的问题
- PAT L2-008. 最长对称子串(25) (暴力,Manacher算法和DP解决)
- 翻转链表-LintCode
- jdk 的下载,安装,以及重装
- CDOJ(UESTC)24 8球胜负(eight)~水题
- Shell 中字符串处理1
- 朱有鹏:对嵌入式工程师的一些小建议
- mybatis 开启日志记录 打印sql语句