World is Exploding
来源:互联网 发布:node.js ejs 开发指南 编辑:程序博客网 时间:2024/06/06 18:53
World is Exploding
.
.
解法:先求出所有Aa
#include <iostream>#include <stdio.h>#include <stdlib.h>#include <math.h>#include <algorithm>#include <string.h>using namespace std;struct Node{ int id, val; bool operator>(Node &t) { return val>t.val; } bool operator<(Node &t) { return val<t.val; }};const int maxn = 60000;long long fb[maxn], fs[maxn], bb[maxn], bs[maxn], f[maxn], b[maxn];Node a[maxn];int n;void insertb(int x) { while (1) { f[x] = f[x]+1; if (x <= 1) break; x = x-(x & (-x)); }}int findb(int x) { int count = 0; while (1) { count = count+f[x]; x = x+(x & (-x)); if (x > n) break; } return count;}void inserts(int x) { while (1) { f[x] = f[x]+1; x = x+(x & (-x)); if (x > n) break; }}int finds(int x) { int count = 0; while (1) { count = count+f[x]; if (x <= 1) break; x = x-(x & (-x)); } return count;}int main() { int tt; while ((scanf("%d", &n)) != EOF) { for (int i = 1; i <= n; i++) { scanf("%d", &a[i].val); a[i].id = i; } sort(a+1, a+1+n); int count = 1; b[a[1].id] = 1; for (int i = 2; i <= n; i++) { if (a[i].val != a[i-1].val) count++; b[a[i].id] = count; } memset(fb, 0, sizeof(fb)); memset(fs, 0, sizeof(fs)); memset(bb, 0, sizeof(bb)); memset(bs, 0, sizeof(bs)); memset(f, 0, sizeof(f)); for (int i = 1; i <= n; i++) { insertb(b[i]); fb[i] = findb(b[i]+1); } memset(f, 0, sizeof(f)); for (int i = n; i >= 1; i--) { insertb(b[i]); bb[i] = findb(b[i]+1); } memset(f, 0, sizeof(f)); for (int i = 1; i <= n; i++) { inserts(b[i]); fs[i] = finds(b[i]-1); } memset(f, 0, sizeof(f)); for (int i = n; i >= 1; i--) { inserts(b[i]); bs[i] = finds(b[i]-1); } long long ans = 0, /*bb*/temp1 = 0, /*bs*/temp2 = 0; for (int i = 1; i <= n; i++) { temp1 += bb[i]; temp2 += bs[i]; } ans = temp1*temp2; for (int i = 1; i <= n; i++) { ans = ans-(fs[i]*bs[i]); ans = ans-(bb[i]*bs[i]); ans = ans-(fs[i]*fb[i]); ans = ans-(fb[i]*bb[i]); } printf("%lld\n", ans); }}
0 0
- 多校 World is Exploding
- hdu5792 World is Exploding
- World is Exploding
- World is Exploding HDU
- HDU 5792 World is Exploding
- HDU 5792 World is Exploding
- HDU 5792 World is Exploding
- HDOJ 5792 World is Exploding
- HDU 5792 World is Exploding
- HDU 5792 World is Exploding
- Hdu 5792 World is Exploding
- hdu 5792 World is Exploding 树状数组
- HDU-5792-World is Exploding-树状数组
- HDU 5792 World is Exploding(BIT)
- 【Wannafly Daily 4.22】World is Exploding
- HDU 5792 World is Exploding (树状数组逆序对)
- HDU5792 World is Exploding (线段树&&逆序数)
- 2016多校训练Contest5: 1012 World is Exploding hdu5792
- GWT @inject annotation
- PHP实现简单高精度的求PI方法
- POJ 2676 数独 && 编程之美1.15
- Spring MVC配置介绍
- oc——NSObject——create copy dealloc
- World is Exploding
- 扑克牌的研究
- Android状态栏微技巧,带你真正理解沉浸式模式
- epoll源码探秘(epoll_create)
- Android代码规范
- 话说Svn与Git的区别
- Linux中的find
- C++11 标准新特性: 右值引用与转移语义
- PreAuthenticatedGrantedAuthoritiesUserDetailsService/DelegatingFilterProxy