HDU 5273Dylans loves sequence
来源:互联网 发布:360网页广告拦截软件 编辑:程序博客网 时间:2024/06/06 20:12
Problem Description
Dylans is given N numbers a[1]....a[N]
And there areQ questions.
Each question is like this(L,R)
his goal is to find the “inversions” from numberL to number R .
more formally,his needs to find the numbers of pair(x,y ),
thatL≤x,y≤R and x<y and a[x]>a[y]
And there are
Each question is like this
his goal is to find the “inversions” from number
more formally,his needs to find the numbers of pair(
that
Input
In the first line there is two numbers N and Q .
Then in the second line there areN numbers:a[1]..a[N]
In the nextQ lines,there are two numbers L,R in each line.
N≤1000,Q≤100000,L≤R,1≤a[i]≤231−1
Then in the second line there are
In the next
Output
For each query,print the numbers of "inversions”
Sample Input
3 23 2 11 21 3
Sample Output
13直接树状数组预处理出所有情况,然后输出即可#include<iostream>#include<cstdio>#include<vector>#include<iostream>#include<queue>#include<cstdlib>#include<map>using namespace std;const int maxn = 1005;const int low(int x){ return x&-x; }int f[maxn];int a[maxn], b[maxn], c[maxn][maxn];map<int, int> M;int n, q, tot, l, r;void add(int x){ for (int i = x; i <= tot; i += low(i)) f[i]++;}int sum(int x){ int ans = 0; for (int i = x; i; i -= low(i)) ans += f[i]; return ans;}int main(){ while (scanf("%d%d", &n, &q) != EOF) { for (int i = 1; i <= n; i++) scanf("%d", &a[i]), b[i - 1] = a[i]; sort(b, b + n); for (int i = tot = 0; i < n; i++) M[b[i]] = ++tot; for (int i = 1; i <= n; i++) { for (int j = 1; j <= tot; j++) f[j] = 0; c[i][i] = 0; add(M[a[i]]); for (int j = i + 1; j <= n; j++) { c[i][j] = c[i][j - 1] + j - i - sum(M[a[j]]); add(M[a[j]]); } } while (q--) { scanf("%d%d", &l, &r); printf("%d\n", c[l][r]); } } return 0;}
0 0
- hdu 5273 Dylans loves sequence
- HDU 5273Dylans loves sequence
- hdu 5273 Dylans loves sequence
- HDU 5273 Dylans loves sequence
- HDU 5273 Dylans loves sequence
- HDU 5273 Dylans loves sequence(区间DP)
- HDU ACM 5273 Dylans loves sequence->DP
- HDU 5273 Dylans loves sequence 区间DP
- hdu 5273 Dylans loves sequence 逆序数 区间dp
- Dylans loves sequence
- HDU5273-Dylans loves sequence
- HDU5273--Dylans loves sequence
- HDU 5273 Dylans loves sequence(线段树求逆序数对+离散化)
- HDU 5273 Dylans loves sequence——BestCoder Round #45(DP or 树状数组)
- 【BC#24 1002 HDOJ 5273】Dylans loves sequence
- HDU 5272 Dylans loves numbers
- HDU 5272Dylans loves numbers
- HDU 5272 Dylans loves numbers
- 黑马程序员——JAVA笔记——File
- 依赖注入的三种实现形式
- HDU 5272Dylans loves numbers
- Java快速教程
- hibernate映谢文件
- HDU 5273Dylans loves sequence
- Ubuntu下配置JDK
- windows的cmd命令
- JAVA词汇大全
- mysql数据库高可用高扩展性架构方案实施
- linux下安装和配置DNS服务器
- 常用sql
- 黑马程序员——JAVA笔记——装饰设计模式
- Java并发编程-32-带有延迟元素的队列-DelayQueue