啊啊啊啊啊 ~~ 我好菜
这道题题意大概是:
求这个序列 任意连续子序列的mex 的mex。
怎么求呢?
还好,, 有一点点想法。
从小到大枚举答案是谁,判断它成不成立,
如何判断呢?
假设枚举的是 x ,如果随便一个区间中没有 x ,并且包含 1 ~ x - 1。
那么这个值肯定可以当答案。
然后 问题就是 怎么判断 随便一个区间中没有 x ,并且包含 1 ~ x - 1 是否成立。
刚开始想的 把x 不在的区间放到vector中,然后 遍历一下,在主席树上找这个区间中包不包含1~x - 1.然后突然发现主席树好像不能这样找,
于是查题解
差不多就是这样的思路。
最后判断那个条件就相当于 从前往后把这个值出现最晚的位置加到线段树中。查询1~i - 1 出现的最前面的位置 是否在上一个a[i] 后面。
可能有点绕。。 但是看代码就一目了然。。
代码:
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <string>
#include <queue>
#include <cstring>
#include <stack>
#include <map>
#include <bitset>
#include <math.h>
#include <set>
#include <unordered_set>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<int,ll> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef unsigned long long ull;
typedef unordered_set<int>::iterator sit;
#define st first
#define sd second
#define mkp make_pair
#define pb push_back
void tempwj(){
freopen("hash.in","r",stdin);freopen("hash.out","w",stdout);}
ll gcd(ll a,ll b){
return b ==