题目连接

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. DB2命令大全

    1.1查看表空间 db2 list tablespaces show detail 1.2查看数据库的表死锁 方法一: 打开监控   db2 update monitor switches using ...

  2. c语言解数独

    来自:http://my.oschina.net/lovewxm/blog/288043?p=1 #include <stdio.h> #include <stdlib.h> ...

  3. PL/SQL 导入excel表格到oracle数据表

    通过使用PL/SQL 批量查询取数时,将excel中的每一列数据复制黏贴进新建的中间表,黏贴时会有贴歪的情况,也就是某些列会从第二第三行开始插入整列,导致数据乱掉,然后好像又不支持批量删除整列数据,所 ...

  4. 【HTML/XML 9】XML中的DTD文件

    导读:DTD是Document type definition(文档类型定义的缩写),是一套关于标记符的语法规则,它是XML文件的验证机制,数以XML文件的组成部分.XML文档是一种描述标记语言的语言 ...

  5. md5的一些用法

    package md5; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; /* * ...

  6. Windows phone 8 学习笔记(7) 设备(转)

    本节主要涉及到 Windows phone 8 手机支持的各类设备,包括相机.设备状态,振动装置等.还有各类感应器,包括磁力计.加速度器和陀螺仪.通过设备状态可以获取内存.硬件.电源.键盘等状态:通过 ...

  7. Magento修改css样式更新之——grunt命令使用

    1.清除pub/static和var中相应文件 2.源头文件重新导入pub/static 3.pub中的less编译 4.字面翻译是跟踪源头文件变化实时编译,但是这里的the source files ...

  8. Android IOS WebRTC 音视频开发总结(四九)-- ffmpeg介绍

    本文主要介绍ffmpeg,文章来自博客园RTC.Blacker,支持原创,转载必须说明出处,个人微信公众号blacker,更多详见www.rtc.help 说明: ps1:如果直接从webrtc开始学 ...

  9. sed的惯常用法

    1:注释掉某一行这个经常会遇到的,把配置文件里某一行注释掉.让他不起作用.sed -i -e ’121 s/^/#/’ /usr/local/apache2/conf/httpd.conf上面一行命令 ...

  10. Mir2源码详解之服务端-登录网关(LoginGate)

    传奇这款游戏,一直对我的影响很大.当年为了玩传奇,逃课,被老师叫过N次家长.言归正传,网上有很多源码,当然了,都是delphi的.并且很多源码还不全, 由于一直学习的c.c++.delphi还真不懂. ...