问题描述:

1009. Triple Inversions (35)

时间限制
300 ms

内存限制
65536 kB

代码长度限制
8000 B

判题程序
Standard

作者
CAO, Peng

Given a list of N integers A1, A2, A3,...AN, there's a famous problem to count the number of inversions in it. An inversion is defined as a pair of indices i < j such that Ai > Aj.

Now we have a new challenging problem. You are supposed to count the number of triple inversions in it. As you may guess, a triple inversion is defined as a triple of indices i < j < k such that Ai > Aj > Ak. For example, in the list {5, 1, 4, 3, 2} there are 4 triple inversions, namely (5,4,3), (5,4,2), (5,3,2) and (4,3,2). To simplify the problem, the list A is given as a permutation of integers from 1 to N.

Input Specification:

Each input file contains one test case. For each case, the first line gives a positive integer N in [3, 105]. The second line contains a permutation of integers from 1 to N and each of the integer is separated by a single space.

Output Specification:

For each case, print in a line the number of triple inversions in the list.

Sample Input:

22
1 2 3 4 5 16 6 7 8 9 10 19 11 12 14 15 17 18 21 22 20 13

Sample Output:

8

总感觉这一题又像是 最大不下降子列 的变形题。。。

先对每个输入的数分别求 它前面比它大的元素的个数r 和 它后面比它小的元素的个数b 两者相乘叠加就AC了;

AC代码(今天学习了平板电视(pb_ds)的相关知识,于是今天的代码变成了(pb_ds)风格的了。。。)

 123456789
10
11
12
13
14
15
16
17
18
19
20
21
22

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
int main()
{
//  freopen("data.txt","r",stdin);tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> tr;long long n,x,s=0;long long r,b;scanf("%lld",&n);for(long long i=1;i<=n;i++){scanf("%lld",&x);tr.insert(x);r=tr.size()-tr.order_of_key(x)-1;b=r-i+x;s=s+r*b;}printf("%lld",s);return 0;
}

PAT TOP 1009. Triple Inversions (35)相关推荐

  1. PAT Top 1022 Werewolf (35)

    PAT Top 1022 Werewolf (35) 题目描述 Input Specification: Output Specification: Sample Input: Sample Outp ...

  2. PAT TOP 1021. Safe Fruit (35)

    问题描述: 1021. Safe Fruit (35) 时间限制 1500 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue Ther ...

  3. 1009 Triple Inversions

    知识点:线段树 这个题一般都是用树状数组做的,但是还没学,现在在学线段树,就用来练习线段树把,就是很一般的权值线段树,难度是洛谷绿题,洛谷有和这个一模一样的题 #include <bits/st ...

  4. PAT (Top Level) Practise 1008 Airline Routes(Tarjan模版题)

    1008. Airline Routes (35) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue Given a ...

  5. PAT甲级1009 Product of Polynomials:[C++题解]多项式乘法、高精度乘法

    文章目录 题目分析 题目链接 题目分析 多项用一个数组来表示,数组下标表示多项式的次幂,存的内容表示多项式的系数. 然后用两重循环来计算多项式的乘法: for i : 第二个式子for j:第一个式子 ...

  6. PAT 乙级 1009

    题目 题目地址:PAT 乙级 1009 题解 本题本身属于比较简单的字符串操作题,但是因为对于string的操作和函数不熟悉导致本题做起来很费劲,需要加强对于string类以及相关方法的理解和熟练程度 ...

  7. PAT甲级1009 Product of Polynomials (25分)

    PAT甲级1009 Product of Polynomials (25分) 题目: 题目分析:和之前有一道多项式相加很像,注意点是不仅仅数组系数会变,还可能会出现之前没有的指数,因此要开2001大小 ...

  8. PAT乙级——1009 说反话

    题目:PAT乙级--1009 说反话 分析: 看到题目,就是要把字符串倒序输出.可以设置一个vector容器存字符串,存好之后倒序输出即可 注意: cin>>s 读取字符串需要加头文件st ...

  9. PAT TOP 1001 Battle Over Cities - Hard Version (35)

    问题描述: 1001 Battle Over Cities - Hard Version (35 分) It is vitally important to have all the cities c ...

最新文章

  1. linux下导入、导出mysql数据库命令
  2. vim ctrlp_使用Ctrlp和Ctag使Vim更智能
  3. 公共界面_公共建筑东营市档案馆能耗计量分析系统
  4. mysql统计每个科目平均成绩_No.03 数据库经典面试之如何取出每科成绩的前三名...
  5. react动态改变选中不选中_reactjs – 如何避免使用重新选择来计算派生状态时React重新渲染...
  6. 保定2021高考成绩查询,保定2021年中考网上查询
  7. mysql cmd 实时监控_mysql实时监听sql语句
  8. Flex4 Skinning 1: 自定义一个简单按钮的皮肤
  9. multisim10中设置变压器匝数比的两种方法
  10. 公司内部Wiki及搭建wiki系统-confluence
  11. (最详细)小米手机4c的USB调试模式在哪里开启的教程
  12. C++ 实现大小写转换
  13. 【散文诗】STM32时钟框图
  14. 给IT新人的15个建议:苦逼程序员的辛酸反省与总结!
  15. 移动硬盘无法访问设备未就绪资料找到的法子
  16. docker build 时出现no space left on device解决方法
  17. M5stack StickCplus ESP32物联网开发板初体验
  18. python画三维坐标图像_用python检索xyz坐标并绘制三维图形
  19. 大数据转型方案:首推数据湖!
  20. linux多进程能同时执行吗,Linux开发简单多进程应用

热门文章

  1. 实现网页自适应不同尺寸 屏幕(PC端)
  2. python数据清洗的方法有哪些_7步搞定数据清洗-Python数据清洗指南
  3. HTML5期末大作业:城市旅游网站设计——城市旅游-北京(5页) HTML+CSS+JavaScript 主题度假酒店 计划出行北京
  4. 快速安装小乌龟svn
  5. TeoreX PhotoScissors v5.0绿色中文版 [一键抠图工具]
  6. 详细图解二叉树四种遍历(前序中序后序层次遍历)
  7. C++ 读取h264中的nalu
  8. 菜鸟学习NodeJS笔记(一)
  9. 2022秋中国海洋大学《软件工程》第14小组第三次作业
  10. 服务器可以用来做监控系统吗,服务器可以做监控主机吗