题目的大致意思是有一个数组,然后有Q个询问,对于每次询问给出L和R,然后要给出每次L和R区间内的逆序对个数。
解答方法就是先算出ans[0][1...N-1]的结果,然后根据再来算ans[i][i+1...N-1](0<i<N),ans[i][j] 跟ans[i-1][j]相比就是要减去第i个数字的影响,所以开一个累加器即可。
#include "stdio.h"
#include "string.h"
#include "math.h"
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
using namespace std;
#define MAXM 1
#define MAXN 1
#define max(a,b) a > b ? a : b
#define min(a,b) a < b ? a : b
#define Mem(a,b) memset(a,b,sizeof(a))
int Mod = 1000000007;
double pi = acos(-1.0);
double eps = 1e-6;
typedef struct{
int f,t,w,next;
}Edge;
Edge edge[MAXM];
int head[MAXN];
int kNum;
typedef long long LL;
void addEdge(int f, int t, int w)
{
edge[kNum].f = f;
edge[kNum].t = t;
edge[kNum].w = w;
edge[kNum].next = head[f];
head[f] = kNum ++;

博客探讨了如何处理数组中区间逆序对的问题,提出了通过预处理和累加器来解决Q次询问的方法,详细解释了如何减去特定元素影响以获取正确答案。
最低0.47元/天 解锁文章
6万+

被折叠的 条评论
为什么被折叠?



