题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=5273

Dylans loves sequence

Description

Dylans is given $N$ numbers $a[1]....a[N]$

And there are $Q$ questions.

Each question is like this $(L,R)$

his goal is to find the “inversions” from number $L$ to number $R.$

more formally,his needs to find the numbers of pair$(x,y)$,
that $L \leq x,y \leq R$ and $ x < y $ and $a[x] > a[y]$

Input

In the first line there is two numbers $N$ and $Q.$

Then in the second line there are $N$ numbers:$a[1]..a[N]$

In the next $Q$ lines,there are two numbers $L,R$ in each line.

$N \leq 1000, Q \leq 100000, L \leq R, 1 \leq a[i] \leq 2^{31}-1$

Output

For each query,print the numbers of "inversions”

SampleInput

3 2
3 2 1
1 2
1 3

SampleOutput

1

3

 #include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<map>
#include<set>
using std::cin;
using std::cout;
using std::endl;
using std::find;
using std::sort;
using std::set;
using std::map;
using std::pair;
using std::vector;
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cls(arr,val) memset(arr,val,sizeof(arr))
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define fork(i, k, n) for(int i = (int)k; i<= (int)n; i++)
#define forp(i, k, p) for(int i = (int)k; i > p; i--)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
const int Max_N = ;
typedef unsigned long long ull;
int dp[Max_N][Max_N], arr[Max_N];
int main() {
#ifdef LOCAL
freopen("in.txt","r",stdin);
freopen("out.txt","w+",stdout);
#endif
int n, q, x, y;
while(~scanf("%d %d",&n, &q)) {
rep(i,n) scanf("%d",&arr[i + ]);
cls(dp, );
fork(i, , n) {
fork(j, i + , n) dp[i][j] += dp[i][j - ] + (int)(arr[i] > arr[j]);
}
forp(j, n, ) {
forp(i, j ,) dp[i][j] += dp[i + ][j];
}
rep(i, q) scanf("%d %d",&x, &y), printf("%d\n",dp[x][y]);
}
return ;
}

hdu 5273 Dylans loves sequence的更多相关文章

  1. hdu 5273 Dylans loves sequence 逆序数简单递推

    Dylans loves sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem ...

  2. HDU 5273 Dylans loves sequence 暴力递推

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5273 bc:http://bestcoder.hdu.edu.cn/contests/con ...

  3. HDU 5273 Dylans loves sequence (逆序对,暴力)

    题意: 给定一个序列,对于q个询问:(L,R)之间有几个逆序对?序列元素个数上限1000,q上限10万.仅1测试例子. 思路: [L,R]的逆序对数量可以这么算,假设L<=K<R,将区间拆 ...

  4. HDU 5273 Dylans loves sequence【 树状数组 】

    题意:给出n个数,再给出q个询问,求L到R的逆序对的个数 先自己写的时候,是每次询问都重新插入来求sum(r)-sum(l) 果断T 后来还是看了别人的代码---- 预处理一下,把所有可能的区间的询问 ...

  5. HDU 5273 Dylans loves numbers(水题)

    题意:给出一个0≤N≤1018,求其二进制中有几处是具有1的,假设相连的1只算1处,比如1101011就是3处. 思路:一个个数,当遇到第一个1时就将flag置为1:当遇到0就将flag置为0.当遇到 ...

  6. hdu 5274 Dylans loves tree(LCA + 线段树)

    Dylans loves tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Othe ...

  7. Hdu 5274 Dylans loves tree (树链剖分模板)

    Hdu 5274 Dylans loves tree (树链剖分模板) 题目传送门 #include <queue> #include <cmath> #include < ...

  8. Hdu 5806 NanoApe Loves Sequence Ⅱ(双指针) (C++,Java)

    Hdu 5806 NanoApe Loves Sequence Ⅱ(双指针) Hdu 5806 题意:给出一个数组,求区间第k大的数大于等于m的区间个数 #include<queue> # ...

  9. hdu 5272 Dylans loves numbers

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5272 Dylans loves numbers Description Who is Dylans?Y ...

随机推荐

  1. jquery zTree 查找所有的叶子节点

    jquery zTree 查找所有的叶子节点 // 保存所有叶子节点 10 为初始化大小,并非数组上限 var arrayObj = new Array([10]); /* treeNode: 根节点 ...

  2. LA3211 飞机调度 Now or later-二分法&TwoSet

    https://vjudge.net/problem/UVALive-3211 As you must have experienced, instead of landing immediately ...

  3. Android基础总结(8)——服务

    服务(Service)是Android中实现程序后台运行的解决方案,它非常适合用于去执行哪些不需要和用户交互而且还要长期运行的任务.服务的运行不依赖任何用户界面,即使当程序被切换到后台,或者用户打开了 ...

  4. PAT1069. The Black Hole of Numbers

    //这是到水题,之前因为四位数的原因一直不能A,看了别人的程序,才明白,不够四位的时候没考虑到,坑啊.....脸打肿 #include<cstdio>#include<algorit ...

  5. SqlServer 事务和异常处理示例

    BEGIN TRANSACTION--开始事务 DECLARE @errorSun INT --定义错误计数器SET @errorSun=0 --没错为0 UPDATE dbo.Test SET te ...

  6. ittype导师课程 - SAP顾问课程,云课堂,个性辅导

    ittype致力于成为最专业的<企业管理研究+管理信息化需求研究+解决方案+项目+人才>全生态链服务与功能平台,平台网址:www.ittype.com. 平台由导师+学员模式,导师教导学员 ...

  7. 一款非常简单的android音乐播放器源码分享给大家

    一款非常简单的android音乐播放器源码分享给大家,该应用虽然很小,大家常用的播放器功能基本实现了,可能有点还不够完善,大家也可以自己完善一下,源码在源码天堂那里已经有了,大家可以到那里下载学习吧. ...

  8. 开发iOS应用程序需要的工具和编程技术

    似乎每个iOS应用开发学习者都是从这篇文章开始写博客的,我也不例外,也从这里写吧,内容雷同,但绝对是原创.因为一直相信,通过自己的理解写出来,是掌握技术一个很好的途径. Xcode苹果最为优秀的集成开 ...

  9. 软件工程 speedsnail 第二次冲刺4

    20150521 完成任务:划线第四天,能蜗牛遇到线能反弹,加了障碍物: 遇到问题: 问题1 有一个方向碰到线没有反弹 解决1 没有解决 明日任务: 完善问题1

  10. 四、MongoDB的查询

    一.MongoDB的下载.安装与部署 二.MongoDB的基础知识简介 三.MongoDB的创建.更新和删除 db.blogs.insert([ { "author": " ...