Dylans loves sequence

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 372    Accepted Submission(s): 186

Problem 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≤x,y≤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≤1000,Q≤100000,L≤R,1≤a[i]≤231−1

 
Output
For each query,print the numbers of "inversions”
 
Sample Input
3 2
3 2 1
1 2
1 3
 
Sample Output
1
3

Hint

You shouldn't print any space in each end of the line in the hack data.

 
Source
/**
题意:给出一个数列,求某个区间的逆序数对有多少个
做法:因为N 最大1000 所以 枚举,还以为是笼统的归并排序
**/
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <cmath>
#define maxn 1010
using namespace std;
int dp[maxn][maxn];
int mmap[maxn];
int main()
{
//#ifndef ONLINE_JUDGE
// freopen("in.txt","r",stdin);
//#endif // ONLINE_JUDGE
int n,m;
while(~scanf("%d %d",&n,&m))
{
for(int i=;i<=n;i++)
{
scanf("%d",&mmap[i]);
}
memset(dp,,sizeof(dp));
for(int i=;i<=n;i++)
{
for(int j=i+;j<=n;j++)
{
if(mmap[i] > mmap[j])
dp[i][j] ++;
}
for(int j=;j<=n;j++)
{
dp[i][j] += dp[i][j-];
}
}
for(int i=n-;i>;i--) ///枚举i~j中任意一个区间的逆序数对
{
for(int j=i+;j<=n;j++)
{
dp[i][j] += dp[i+][j];
}
}
while(m--)
{
int u,v;
scanf("%d %d",&u,&v);
printf("%d\n",dp[u][v]);
}
}
return ;
}
 

HDU-5273的更多相关文章

  1. hdu 5273 Dylans loves sequence

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5273 Dylans loves sequence Description Dylans is give ...

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

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

  3. HDU 5273 Dylans loves sequence 暴力递推

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

  4. HDU 5273 Dylans loves numbers(水题)

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

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

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

  6. HDU 5273 区间DP

    输入一组数,m次询问 问每一个询问区间的逆序数有多少 区间DP简单题 #include "stdio.h" #include "string.h" int dp ...

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

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

  8. HDU 2680 最短路 迪杰斯特拉算法 添加超级源点

    Choose the best route Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  9. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  10. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

随机推荐

  1. 洛谷 P3959 宝藏 解题报告

    P3959 宝藏 题目描述 参与考古挖掘的小明得到了一份藏宝图,藏宝图上标出了 \(n\) 个深埋在地下的宝藏屋, 也给出了这 \(n\) 个宝藏屋之间可供开发的 \(m\) 条道路和它们的长度. 小 ...

  2. YBT 1.1 贪心算法

    本人因为过于懒所以以后就将题解放进原文件中,存入百度网盘,自行下载,里面包含题目网站,源文件,与相应题解(这次没有写) 链接: https://pan.baidu.com/s/1eSoQ_LFWMxF ...

  3. 使用 Intel HAXM 为eclipse安卓模拟器加速

    一.下载haxm安装 https://software.intel.com/zh-cn/android/articles/intel-hardware-accelerated-execution-ma ...

  4. Ubuntu 16.04安装NVIDIA驱动后循环登录问题

    问题描述 最近买了两块NVIDIA Titan X Pascal显卡装到了服务器(运行Ubuntu 16.04)上.为了使用这两块GPU显卡,首先需要安装显卡驱动,安装方式为 #安装一个依赖文件,并更 ...

  5. Java的四种引用?用到的场景?

    在JDK 1.2以前的版本中,若一个对象不被任何变量引用,那么程序就无法再使用这个对象.也就是说,只有对象处于可触及(reachable)状态,程序才能使用它.从JDK 1.2版本开始,把对象的引用分 ...

  6. nginx 报invalid pid number

    /opt/ibis/sbin/nginx -c /opt/ibis/conf/nginx.conf 这是make make install之后生成的文件夹和文件. -c c是configure的缩写 ...

  7. MFC单文档多视图程序设计与Splitter拆分窗口

    1. 创建不同的子frame. 在文档视图程序中 CMainFrame(class CMainFrame : public CMDIFrameWndEx) 继承自 CMDIFrameWnd (CMDI ...

  8. ACM2112迪克斯特算法

    HDU Today Problem Description 经过锦囊相助,海东集团终于度过了危机,从此,HDU的发展就一直顺风顺水,到了2050年,集团已经相当规模了,据说进入了钱江肉丝经济开发区50 ...

  9. shell编程:条件测试与比较(六)

    条件测试方法综述 test条件测试的简单语法及测试 范例6-1 测试文件(在test命令中使用-f选项:文件存在且为不同文件则表达式成立) [root@adminset ~]# test -f fil ...

  10. linux查看内存cpu占用

    linux查看内存cpu占用top 命令  按q退出 可以添加额外选项选择按进程或按用户查看如: top -u gitu PID:进程idPR:进程的优先级别,越小越优先被执行NInice:值VIRT ...