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. 1 #include <cstdio>
  2. 2 #include <cstdlib>
  3. 3 #include <cstring>
  4. 4 #include <cmath>
  5. 5 #include <iostream>
  6. 6 #include <algorithm>
  7. 7 #include <map>
  8. 8 #include <queue>
  9. 9 #include <vector>
  10. 10 #include<set>
  11. 11 using namespace std;
  12. 12 typedef long long LL;
  13. 13 typedef struct pp
  14. 14 {
  15. 15 int x;
  16. 16 int id;
  17. 17 } ss;
  18. 18 bool cmp(pp p,pp q)
  19. 19 {
  20. 20 return p.x<q.x;
  21. 21 }
  22. 22 int uu[6000];
  23. 23 ss dd[60000];
  24. 24 int a[60000];
  25. 25 LL zbit[60000];
  26. 26 LL ybit[60000];
  27. 27 int zz[60000];
  28. 28 int yy[60000];
  29. 29 int zz1[60000];
  30. 30 int yy1[60000];
  31. 31 int sumz(int i);
  32. 32 void addz(int i,int x,int t);
  33. 33 int sumy(int i);
  34. 34 void addy(int i,int x,int t);
  35. 35 int main(void)
  36. 36 {
  37. 37 LL i,j,k;
  38. 38 while(scanf("%lld",&k)!=EOF)
  39. 39 {
  40. 40 for(i=0; i<k; i++)
  41. 41 {
  42. 42 scanf("%d",&dd[i].x);
  43. 43 dd[i].id=i;
  44. 44 }
  45. 45 memset(zbit,0,sizeof(zbit));
  46. 46 memset(ybit,0,sizeof(ybit));
  47. 47 sort(dd,dd+k,cmp);
  48. 48 int id=1;
  49. 49 int ak=dd[0].x;
  50. 50 a[dd[0].id]=id;
  51. 51 for(i=1; i<k; i++)
  52. 52 {
  53. 53 if(ak!=dd[i].x)
  54. 54 {
  55. 55 id++;
  56. 56 ak=dd[i].x;
  57. 57 }
  58. 58 a[dd[i].id]=id;
  59. 59 }
  60. 60 for(i=0; i<k; i++)
  61. 61 {
  62. 62 LL ask=sumz(a[i]-1);
  63. 63 zz[i]=ask;
  64. 64 zz1[i]=i-sumz(a[i]);
  65. 65 addz(a[i],1,id);
  66. 66 }
  67. 67 for(i=k-1; i>=0; i--)
  68. 68 {
  69. 69 LL ask=sumy(a[i]-1);
  70. 70 yy[i]=ask;
  71. 71 yy1[i]=(k-i-1)-sumy(a[i]);
  72. 72 addy(a[i],1,id);
  73. 73 }
  74. 74 LL qian=0;
  75. 75 LL hou=0;
  76. 76 for(i=0; i<k; i++)
  77. 77 {
  78. 78 qian+=zz[i];
  79. 79 hou+=yy[i];
  80. 80 }
  81. 81 LL sum=qian*hou;
  82. 82 for(i=0; i<k; i++)
  83. 83 {
  84. 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. 85 }
  86. 86 printf("%lld\n",sum);
  87. 87 }
  88. 88 return 0;
  89. 89 }
  90. 90 int sumz(int i)
  91. 91 {
  92. 92 int s=0;
  93. 93 while(i>0)
  94. 94 {
  95. 95 s+=zbit[i];
  96. 96 i-=i&(-i);
  97. 97 }
  98. 98 return s;
  99. 99 }
  100. 100 void addz(int i,int x,int t)
  101. 101 {
  102. 102 while(i<=t)
  103. 103 {
  104. 104 zbit[i]+=x;
  105. 105 i+=i&(-i);
  106. 106 }
  107. 107 }
  108. 108 int sumy(int i)
  109. 109 {
  110. 110 int s=0;
  111. 111 while(i>0)
  112. 112 {
  113. 113 s+=ybit[i];
  114. 114 i-=i&(-i);
  115. 115 }
  116. 116 return s;
  117. 117 }
  118. 118 void addy(int i,int x,int t)
  119. 119 {
  120. 120 while(i<=t)
  121. 121 {
  122. 122 ybit[i]+=x;
  123. 123 i+=i&(-i);
  124. 124 }
  125. 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. 在Idea上用JDBC连接mysql数据库

    一.前言 本次操作建立在idea中java环境已配置的基础上 二.操作步骤 1.建立Web项目后,添加驱动包 mysql-connector-java-5.0.8-bin.jar (1)下载mysql ...

  2. [C++] vptr, where are you?

    Search(c++在线运行). 有的网站很慢--不是下面的程序有问题. #include <string.h> #include <stdio.h> #include < ...

  3. COAP协议 - arduino ESP32 M2M(端对端)通讯与代码详解

    前言 最近我在研究 COAP 协议,在尝试使用 COAP 协议找了到了一个能在ESP32上用的coap-simple库,虽然库并不完善关于loop处理的部分应该是没写完,但是对于第一次接触COAP的朋 ...

  4. Maven 目录结构[转载]

    转载至:http://www.cnblogs.com/haippy/archive/2012/07/05/2577233.html Maven 标准目录结构 好的目录结构可以使开发人员更容易理解项目, ...

  5. ubantu打开摄像头失败

    摘要-针对ubantu20 sudo apt install v4l-utils v4l2-ctl --list-devices - cv2 install on ubantu20```针对ubant ...

  6. AI ubantu 环境安装

    ubantu安装记录 apt install python3-pip anaconda安装 https://repo.anaconda.com/archive/Anaconda3-2020.11-Li ...

  7. Linux学习 - 变量测试与内容替换

    变量置换方式 变量y没有设置 变量y为空 变量y有值 x=${y-新值} x=新值 x空 x=$y x=${y:-新值} x=新值 x=新值 x=$y x=${y+新值} x空 x=新值 x=新值 x ...

  8. Linux系统信息查看命令(ZZ)

    http://hi.baidu.com/thinkdifferent/blog/item/22f4a80161630e011d958384.html转自一个baidu师兄的博客,很好的一个总结,推荐下 ...

  9. shell脚本实现openss自建CA和证书申请

    #!/bin/bash # #******************************************************************** #Author: Ma Xue ...

  10. Ajax请求($.ajax()为例)中data属性传参数的形式

    首先定义一个form表单: <form id="login" > <input name="user" type="text&quo ...