题意:

给出序列 a1,a2,……an(0≤ai≤109),求三元组(ai,aj,ak)(1≤i<j<k≤n)满足 ai<aj>ak 的数量。

分析:

开两个\(BIT\),分别维护前面比它小的和后面比它大的,然后组合计数一下即可

代码:

#include<bits/stdc++.h>
#define lowbit(x) (x & (-x))
#define ll long long
#define N (100000 + 5)
using namespace std;
inline int read() {
int cnt = 0, f = 1; char c = getchar();
while (!isdigit(c)) {if (c == '-') f = -f; c = getchar();}
while (isdigit(c)) {cnt = (cnt << 3) + (cnt << 1) + c - '0'; c = getchar();}
return cnt * f;
}
int n, q, a[N], b[N << 1];
ll ans;
void pre() {
sort(b + 1, b + n + 1);
q = unique(b + 1, b + n + 1) - b - 1;
for (register int i = 1; i <= n; ++i) a[i] = lower_bound(b + 1, b + q + 1, a[i]) - b;
}
struct node {
int BIT[N];
void insert (int x) {for (; x <= n; x += lowbit(x)) ++BIT[x];}
void Delete (int x) {for (; x <= n; x += lowbit(x)) --BIT[x];}
ll query(int x) {ll ans = 0; for (; x; x -= lowbit(x)) ans += BIT[x]; return ans;}
}BIT1, BIT2;
int main() {
n = read();
for (register int i = 1; i <= n; ++i) a[i] = b[i] = read();
pre();
for (register int i = 1; i <= n; ++i) BIT2.insert(a[i]);
BIT1.insert(a[1]);
for (register int i = 2; i <= n; ++i) {
BIT1.insert(a[i]);
BIT2.Delete(a[i - 1]);
ans += (BIT1.query(a[i] - 1) * (BIT2.query(a[i] - 1)));
// cout<<BIT1.query(a[i] - 1)<< " " << BIT2.query(a[i])<<"\n";
}
printf("%lld", ans);
return 0;
}

Super OJ 序列计数的更多相关文章

  1. [Sdoi2017]序列计数 [矩阵快速幂]

    [Sdoi2017]序列计数 题意:长为\(n \le 10^9\)由不超过\(m \le 2 \cdot 10^7\)的正整数构成的和为\(t\le 100\)的倍数且至少有一个质数的序列个数 总- ...

  2. BZOJ_4818_[Sdoi2017]序列计数_矩阵乘法

    BZOJ_4818_[Sdoi2017]序列计数_矩阵乘法 Description Alice想要得到一个长度为n的序列,序列中的数都是不超过m的正整数,而且这n个数的和是p的倍数.Alice还希望 ...

  3. HDU 6348 序列计数 (树状数组 + DP)

    序列计数 Time Limit: 4500/4000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Subm ...

  4. luogu3702-[SDOI2017]序列计数

    Description Alice想要得到一个长度为nn的序列,序列中的数都是不超过mm的正整数,而且这nn个数的和是pp的倍数. Alice还希望,这nn个数中,至少有一个数是质数. Alice想知 ...

  5. BZOJ4818 序列计数

    4818: [Sdoi2017]序列计数 Time Limit: 30 Sec  Memory Limit: 128 MB Description Alice想要得到一个长度为n的序列,序列中的数都是 ...

  6. 【BZOJ 4818】 4818: [Sdoi2017]序列计数 (矩阵乘法、容斥计数)

    4818: [Sdoi2017]序列计数 Time Limit: 30 Sec  Memory Limit: 128 MBSubmit: 560  Solved: 359 Description Al ...

  7. P3702 [SDOI2017]序列计数

    P3702 [SDOI2017]序列计数 链接 分析: 首先可以容斥掉,用总的减去一个质数也没有的. 然后可以dp了,f[i][j]表示到第i个数,和在模p下是j的方案数,矩阵快速幂即可. 另一种方法 ...

  8. 【BZOJ4818】[Sdoi2017]序列计数 DP+矩阵乘法

    [BZOJ4818][Sdoi2017]序列计数 Description Alice想要得到一个长度为n的序列,序列中的数都是不超过m的正整数,而且这n个数的和是p的倍数.Alice还希望 ,这n个数 ...

  9. BZOJ4818 LOJ2002 SDOI2017 序列计数 【矩阵快速幂优化DP】*

    BZOJ4818 LOJ2002 SDOI2017 序列计数 Description Alice想要得到一个长度为n的序列,序列中的数都是不超过m的正整数,而且这n个数的和是p的倍数. Alice还希 ...

随机推荐

  1. CentOS提示::unknown filesystem type 'ntfs'自动挂载NTFS分区的U盘或者移动硬盘

    CentOS默认源里没有NTFS-3G,想要添加ntfs支持,无非是自己下载编译安装或者加源yum安装.重新安装了一个CentOS7,用的是添加aliyun的epel源来yum安装的方式,简单易行. ...

  2. Can't finish GitHub sharing process Successfully created project 'springcloud-parent' on GitHub,

    解决Can't finish GitHub sharing process Successfully created project '' on GitHub, but initial push fa ...

  3. 2018阿里云云数据库RDS核心能力演进

    摘要: 2018年云数据库RDS发展上,不但针对MySQL.SQL Server.PostgreSQL提供了适合个人入门用户的基础版产品,以实惠的价格普惠广大中小用户.更加入最新的MariaDB TX ...

  4. C++之string

    一.常用操作 二.用“+”连接字符串的注意事项

  5. java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)

    :: - [localhost-startStop-] INFO - Root WebApplicationContext: initialization started -- :: - [local ...

  6. jeecg下实现自动默认模糊查询

    也许jeecg的作者深受SAP毒害吧,没考虑到广大使用JEECG的人群为SAP用户,及所开发的项目均为中小项目,无惧大数据模糊查询带来的功能影响. 经网友“&&康&&& ...

  7. GPIO, AFIO

    o read/write the AFIO_EVCR, AFIO_MAPR and AFIO_EXTICRX registers, the AFIO clock should first be ena ...

  8. word 文献标题自动编号

    来自:word中自动编号和多级编号的使用 选中标题或段落,点击鼠标右键,在编号菜单内选择适合的自动编号样式.或者在窗口上方的“开始”选项卡中选择编号样式.如果对已选的编号样式不满意,可以照以上方法直接 ...

  9. 4-MySQL高级-事务-提交(3)

    提交 为了演示效果,需要打开两个终端窗口,使用同一个数据库,操作同一张表 step1:连接 终端1:查询商品分类信息 select * from goods_cates; step2:增加数据 终端2 ...

  10. (二十三)Http请求的处理过程