题目
给出一个长度为 n 的排列 P(P1,P2,…,Pn) ,以及 m 个询问。每次询问某个区间 [l,r] 中, 最长的值域连续段长度
这个题目很容易的可以看出来这是一个莫对的题目,然后就能够做出来优秀的O(n sqrn logn )的线段树+莫对的算法,于是…
这是我的结果
这是大佬的分数
**其实这个题目考的是卡常 **
废话了半天就来说一下这个优秀的(可以让大佬A掉的优秀算法)
直接套线段树进行合并,用莫对简单的维护一下
上一下我特别慢的代码
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
#define re register
#define gc getchar()
#define ll long long
inline int read()
{
re int x(0); re char ch(gc);
while(ch>'9'||ch<'0') ch=gc;
while(ch>='0'&&ch<='9') x=(x*10)+(ch^48),ch=gc;
return x;
}
const int N=50010;
int a[N],n,m,num[N];
int size,ku[N]