World is Exploding

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 566    Accepted Submission(s): 263

Problem Description
Given a sequence A with length n,count how many quadruple (a,b,c,d) satisfies: a≠b≠c≠d,1≤a<b≤n,1≤c<d≤n,Aa<Ab,Ac>Ad.
 
Input
The input consists of multiple test cases.
Each test case begin with an integer n in a single line.

The next line contains n integers A1,A2⋯An.
1≤n≤50000
0≤Ai≤1e9
 
Output
For each test case,output a line contains an integer.
 
Sample Input
4
2 4 1 3
4
1 2 3 4
 Sample Output
1
0
 Author
ZSTU
思路:找每个数的前面比他小的个数a[i],和前面比他大的个数,和后面比他小的b[i],和后面比他大的,这个用树状数组求,然后总的个数就是sum(a[i])*sum(b[i]);
然后就是去掉不合情况的,那么就是三个点有一个点是重合的,那么考虑每个节点,就是前面比他小的*后面比他小的,前面比他大的*后面后面比他大的,前面比他小的*前面比他大的,后面比他大的*后面比他小的。
复杂度(n*longn)
  1 #include <cstdio>
2 #include <cstdlib>
3 #include <cstring>
4 #include <cmath>
5 #include <iostream>
6 #include <algorithm>
7 #include <map>
8 #include <queue>
9 #include <vector>
10 #include<set>
11 using namespace std;
12 typedef long long LL;
13 typedef struct pp
14 {
15 int x;
16 int id;
17 } ss;
18 bool cmp(pp p,pp q)
19 {
20 return p.x<q.x;
21 }
22 int uu[6000];
23 ss dd[60000];
24 int a[60000];
25 LL zbit[60000];
26 LL ybit[60000];
27 int zz[60000];
28 int yy[60000];
29 int zz1[60000];
30 int yy1[60000];
31 int sumz(int i);
32 void addz(int i,int x,int t);
33 int sumy(int i);
34 void addy(int i,int x,int t);
35 int main(void)
36 {
37 LL i,j,k;
38 while(scanf("%lld",&k)!=EOF)
39 {
40 for(i=0; i<k; i++)
41 {
42 scanf("%d",&dd[i].x);
43 dd[i].id=i;
44 }
45 memset(zbit,0,sizeof(zbit));
46 memset(ybit,0,sizeof(ybit));
47 sort(dd,dd+k,cmp);
48 int id=1;
49 int ak=dd[0].x;
50 a[dd[0].id]=id;
51 for(i=1; i<k; i++)
52 {
53 if(ak!=dd[i].x)
54 {
55 id++;
56 ak=dd[i].x;
57 }
58 a[dd[i].id]=id;
59 }
60 for(i=0; i<k; i++)
61 {
62 LL ask=sumz(a[i]-1);
63 zz[i]=ask;
64 zz1[i]=i-sumz(a[i]);
65 addz(a[i],1,id);
66 }
67 for(i=k-1; i>=0; i--)
68 {
69 LL ask=sumy(a[i]-1);
70 yy[i]=ask;
71 yy1[i]=(k-i-1)-sumy(a[i]);
72 addy(a[i],1,id);
73 }
74 LL qian=0;
75 LL hou=0;
76 for(i=0; i<k; i++)
77 {
78 qian+=zz[i];
79 hou+=yy[i];
80 }
81 LL sum=qian*hou;
82 for(i=0; i<k; i++)
83 {
84 sum-=(LL)(zz[i])*(LL)(yy[i])+(LL)(zz[i])*(LL)(zz1[i])+(LL)(yy[i])*(LL)(yy1[i])+(LL)(zz1[i])*(LL)(yy1[i]);
85 }
86 printf("%lld\n",sum);
87 }
88 return 0;
89 }
90 int sumz(int i)
91 {
92 int s=0;
93 while(i>0)
94 {
95 s+=zbit[i];
96 i-=i&(-i);
97 }
98 return s;
99 }
100 void addz(int i,int x,int t)
101 {
102 while(i<=t)
103 {
104 zbit[i]+=x;
105 i+=i&(-i);
106 }
107 }
108 int sumy(int i)
109 {
110 int s=0;
111 while(i>0)
112 {
113 s+=ybit[i];
114 i-=i&(-i);
115 }
116 return s;
117 }
118 void addy(int i,int x,int t)
119 {
120 while(i<=t)
121 {
122 ybit[i]+=x;
123 i+=i&(-i);
124 }
125 }

World is Exploding(hdu5792)的更多相关文章

  1. hdu-5792 World is Exploding(容斥+树状数组)

    题目链接: World is Exploding Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Jav ...

  2. HDU5792 World is Exploding(树状数组)

    一共6种情况,a < b且Aa < Ab, c < d 且Ac > Ad,这两种情况数量相乘,再减去a = c, a = d, b = c, b = d这四种情况,使用树状数组 ...

  3. HDU-5792 World is Exploding(树状数组)

    题目大意:给一个整数序列,统计四元组(a,b,c,d)的个数,满足条件1:a<>b<>c<>d:条件2:<a,b>组成一个顺序对,<c,d> ...

  4. hdu5792 World is Exploding(多校第五场)树状数组求逆序对 离散化

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=5792 题目描述:给你n个值,每个值用A[i]表示,然后问你能否找到多少组(a,b,c,d)四个编号,四 ...

  5. HDU 5792---2016暑假多校联合---World is Exploding

    2016暑假多校联合---World is Exploding Problem Description Given a sequence A with length n,count how many ...

  6. 2016 Multi-University Training Contest 5 World is Exploding

    转载自:http://blog.csdn.net/queuelovestack/article/details/52096337 [题意]给你一个序列A,选出四个下标不同的元素,下标记为a,b,c,d ...

  7. HDU 5792 World is Exploding 树状数组+枚举

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5792 World is Exploding Time Limit: 2000/1000 MS (Ja ...

  8. 2016 Multi-University Training Contest 5 1012 World is Exploding 树状数组+离线化

    http://acm.hdu.edu.cn/showproblem.php?pid=5792 1012 World is Exploding 题意:选四个数,满足a<b and A[a]< ...

  9. HDU 5792 World is Exploding (树状数组)

    World is Exploding 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5792 Description Given a sequence ...

随机推荐

  1. 14-Reverse Integer

    思路: 先判定符号,整型范围[-2^32,2^32] 取余除10操作,依次进行,越界返回0 Reverse digits of an integer. Example1: x = 123, retur ...

  2. 谈一谈 DDD

    一.前言 最近 10 年的互联网发展,从电子商务到移动互联,再到"互联网+"与传统行业的互联网转型,是一个非常痛苦的转型过程.在这个过程中,一方面会给我们带来诸多的挑战,另一方面又 ...

  3. 学习java的第十天

    一.今日收获 1.java完全学习手册第二章2.9程序流程控制中的选择结构与顺序结构的例题 2.观看哔哩哔哩上的教学视频 二.今日问题 1.例题的问题不大,需要注意大小写,新的语句记忆不牢 2.哔哩哔 ...

  4. 浅讲.Net 6 之 WebApplicationBuilder

    介绍 .Net 6为我们带来的一种全新的引导程序启动的方式.与之前的拆分成Program.cs和Startup不同,整个引导启动代码都在Program.cs中. WebApplicationBuild ...

  5. 文件读写以及NMEA码中GPS信息的提取

    首先先了解下什么是NMEA码,这里有很好的解释,就不直接搬运了 http://www.gpsbaby.com/wz/nmea.html 首先要找到包含GPS信息的文本行,即字符串GPGGA所在行 $G ...

  6. zabbix之邮件报警

    创建媒介类型 如果用QQ邮箱的话,先设置一下授权码 为用户设置报警 创建一个用户 配置动作 测试

  7. UILabel总结

    UILabel 能显示文字,不能直接通过addTarget...方法监听点击 1. 常见属性 @property(nonatomic,copy) NSString *text; 显示文字 @prope ...

  8. 【Linux】【Services】【SaaS】Docker+kubernetes(6. 安装和配置ceph)

    1. 简介 1.1. 这个在生产中没用上,生产上用的是nfs,不过为了显示咱会,也要写出来 1.2. 官方网站:http://ceph.com/ 1.3. 中文网站:http://docs.ceph. ...

  9. jQuery - focusin/focusout/focus/blur事件的区别与不同

    focus与blur事件:不支持冒泡 focusin与focusout:支持冒泡 事件触发顺序: 对于同时支持这4个事件的浏览器,事件执行顺序为focusin(聚焦) > focus > ...

  10. 07-Spring5 WebFlux响应式编程

    SpringWebFlux介绍 简介 SpringWebFlux是Spring5添加的新模块,用于Web开发,功能和SpringMvc类似的,WebFlux使用当前一种比较流行的响应式编程框架 使用传 ...