World is Exploding(hdu5792)
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
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
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)的更多相关文章
- hdu-5792 World is Exploding(容斥+树状数组)
题目链接: World is Exploding Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Jav ...
- HDU5792 World is Exploding(树状数组)
一共6种情况,a < b且Aa < Ab, c < d 且Ac > Ad,这两种情况数量相乘,再减去a = c, a = d, b = c, b = d这四种情况,使用树状数组 ...
- HDU-5792 World is Exploding(树状数组)
题目大意:给一个整数序列,统计四元组(a,b,c,d)的个数,满足条件1:a<>b<>c<>d:条件2:<a,b>组成一个顺序对,<c,d> ...
- hdu5792 World is Exploding(多校第五场)树状数组求逆序对 离散化
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=5792 题目描述:给你n个值,每个值用A[i]表示,然后问你能否找到多少组(a,b,c,d)四个编号,四 ...
- HDU 5792---2016暑假多校联合---World is Exploding
2016暑假多校联合---World is Exploding Problem Description Given a sequence A with length n,count how many ...
- 2016 Multi-University Training Contest 5 World is Exploding
转载自:http://blog.csdn.net/queuelovestack/article/details/52096337 [题意]给你一个序列A,选出四个下标不同的元素,下标记为a,b,c,d ...
- HDU 5792 World is Exploding 树状数组+枚举
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5792 World is Exploding Time Limit: 2000/1000 MS (Ja ...
- 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]< ...
- HDU 5792 World is Exploding (树状数组)
World is Exploding 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5792 Description Given a sequence ...
随机推荐
- 单片机ISP、IAP和ICP几种烧录方式的区别
单片机ISP.IAP和ICP几种烧录方式的区别 玩单片机的都应该听说过这几个词.一直搞不太清楚他们之间的区别.今天查了资料后总结整理如下. ISP:In System Programing,在系统编程 ...
- APP工程师接入Telink Mesh流程 -3
加密是为了使网络更加的安全.健壮,若由于login.加密等流程 严重影响了 开发进程,也可以通过 修改SDK 固件 将login.加密 环节取消 1.发送数据.接受数据加密,解密去掉 mesh_sec ...
- IPFS是什么?IPFS原理、IPFS存储
以下内容调研截止到2021/11/5日 IPFS简介 IPFS是一种内容可寻址.点对点.分布式文件系统.IPFS采用内容-地址寻址技术,即通过文件内容进行检索而不是通过文件的网络地址.简单来说,就是对 ...
- java输入代码
import java.util.Scanner; public class Demo59 { public static void main(String[] args) { / ...
- python写的多项式符号乘法
D:\>poly.py(x - 1) * (x^2 + x + 1) = x^3 - 1 1 import ply.lex as lex # pip install ply 2 import p ...
- IT四大名著
标题耸人听闻,sorry. CPU.操作系统.编译器和数据库我都不会.我英语也不行,但我认识所有的字母.:-) 万一有人感兴趣呢?https://sqlite.org/doclist.htmlThe ...
- [云原生]Docker - 镜像
目录 Docker镜像 获取镜像 列出本地镜像 创建镜像 方法一:修改已有镜像 方法二:通过Dockerfile构建镜像 方法三:从本地文件系统导入 上传镜像 保存和载入镜像 移除本地镜像 镜像的实现 ...
- C/C++ Qt 数据库与SqlTableModel组件应用
SqlTableModel 组件可以将数据库中的特定字段动态显示在TableView表格组件中,通常设置QSqlTableModel类的变量作为数据模型后就可以显示数据表内容,界面组件中则通过QDat ...
- linux 磁盘满了,vim 编辑文件时无法保存
早上来发现 redis 不能用,报 MISCONF Redis is configured to save RDB snapshots, but it is currently not able to ...
- 深度学习初探——符号式编程、框架、TensorFlow
一.命令式编程(imperative)和符号式编程(symblic) 命令式: import numpy as np a = np.ones(10) b = np.ones(10) * 2 c = b ...