hdu 5273 Dylans loves sequence
题目连接
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的更多相关文章
- hdu 5273 Dylans loves sequence 逆序数简单递推
Dylans loves sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem ...
- HDU 5273 Dylans loves sequence 暴力递推
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5273 bc:http://bestcoder.hdu.edu.cn/contests/con ...
- HDU 5273 Dylans loves sequence (逆序对,暴力)
题意: 给定一个序列,对于q个询问:(L,R)之间有几个逆序对?序列元素个数上限1000,q上限10万.仅1测试例子. 思路: [L,R]的逆序对数量可以这么算,假设L<=K<R,将区间拆 ...
- HDU 5273 Dylans loves sequence【 树状数组 】
题意:给出n个数,再给出q个询问,求L到R的逆序对的个数 先自己写的时候,是每次询问都重新插入来求sum(r)-sum(l) 果断T 后来还是看了别人的代码---- 预处理一下,把所有可能的区间的询问 ...
- HDU 5273 Dylans loves numbers(水题)
题意:给出一个0≤N≤1018,求其二进制中有几处是具有1的,假设相连的1只算1处,比如1101011就是3处. 思路:一个个数,当遇到第一个1时就将flag置为1:当遇到0就将flag置为0.当遇到 ...
- hdu 5274 Dylans loves tree(LCA + 线段树)
Dylans loves tree Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Othe ...
- Hdu 5274 Dylans loves tree (树链剖分模板)
Hdu 5274 Dylans loves tree (树链剖分模板) 题目传送门 #include <queue> #include <cmath> #include < ...
- Hdu 5806 NanoApe Loves Sequence Ⅱ(双指针) (C++,Java)
Hdu 5806 NanoApe Loves Sequence Ⅱ(双指针) Hdu 5806 题意:给出一个数组,求区间第k大的数大于等于m的区间个数 #include<queue> # ...
- hdu 5272 Dylans loves numbers
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5272 Dylans loves numbers Description Who is Dylans?Y ...
随机推荐
- SQL模式匹配
标准的SQL的模式匹配允许你使用“_”匹配任何单个字符,而“%”匹配任意数目字符(包括零个字符).在 MySQL中,SQL的模式缺省是忽略大小写的.下面显示一些例子.注意在你使用SQL模式时,你不能使 ...
- 关于SVN更新时文件加锁的小结
今天使用SVN更新应用,出现了下面的问题: update D:/workspace/acode/resource/springconf -r 6622 --force Attempted to ...
- linux下DNS设置以及解析顺序
1.编辑/etc/resolv.conf文件,添加如下语句: nameserver dns_ip(例如nameserver 8.8.8.8) 2.如/etc/nsswitch.conf中未包含启用DN ...
- SQL语句基础知识
1.关于SQL语句中exists与not exists的问题 course表如下:课程代号 课程名称 K01 奥运会主题曲 K02 喜爱的专辑 K03 VB技术大全 K04 经典歌曲 K05 个人单曲 ...
- ant风格是什么?
我们在看java技术书籍的过程中,当加载文件时总会遇到是否支持ant风格路径加载,这里说的ant风格是什么意思呢,今天我查了一下,明白了什么意思,现在总结一下 ANT通配符有三种: 通配符 说明 ? ...
- [AngularJS 1] Introduction to AngularJS
introduction:this article is going to introduce AngularJS in generally. I will write it through five ...
- vba 快速定位当前EXCEL最后一栏
工作的需要,有时会对EXCEL数据进行处理,比如格式化,有数据的单元格画横线. 最初,傻傻的,直接用个循环从第1行,一直往后找,判断是否为空,真傻. Function FindLastCell() D ...
- 通用简单的 分页 SQL
select ID,TITLE,CONTENT,USERNAME,REALNAME,UNIT,UNITID,NOWTIMES,ACCEPTERID,ACCEPTERNAM ...
- 【IHttpHandler】在ASP.Net2.0中使用UrlRewritingNet实现链接重写
很多时候我们需要链接转向(Url Rewriting),例如二级域名转向.文章访问链接等场合. 让我们看两个例子: 1 你现在看到的当前作者的博客园的域名: http://jx270.cnblogs. ...
- ASP.NET的SEO: 服务器控件背后——SEO友好的Html和JavaScript
本系列目录 假设你需要从一个页面转向其他页面,下面有很多种方式,你是如何选择的呢?你能清晰的说明理由么? <%--链接的表现形式--%> <asp:Hy ...