BZOJ 3585 mex 莫隊演算法 分塊

2021-08-02 04:27:24 字數 1223 閱讀 3066

time limit: 20 sec memory limit: 128 mb

submit: 973 solved: 513

description

有乙個長度為n的陣列。m次詢問,每次詢問乙個區間內最小沒有出現過的自然數。

input

第一行n,m。

第二行為n個數。

從第三行開始,每行乙個詢問l,r。

output

一行乙個數,表示每個詢問的答案。

sample input

5 5

2 1 0 2 1

3 3

2 3

2 4

1 2

3 5

sample output

1 2

3 0

3 hint

資料規模和約定

對於100%的資料:

1<=n,m<=200000

0<=ai<=109

1<=l<=r<=n

對於30%的資料:

1<=n,m<=1000

source

by 佚名提供

這道題我原來應該發過一篇主席樹的題解~~

#include

#include

#include

#include

#include

using namespace std;

const int m = 200200;

struct dataq[m];

int n,m,belong[m],l[m],r[m],a[m],l=1,r=0;

int f[m],block_ans[m],ans[m],block;

inline int

read()

while(c>='0'&&c<='9')

return

x*f;

}bool data :: operator < (const data &x) const

inline void update(int

x)inline void dndate(int

x)inline int query()

int main()

for(int i=1;i<=m;i++) printf("%d\n",ans[i]);

return

0;}

BZOJ 3585 mex 莫隊演算法

離線處理,這題完全不用離散化直接無視 n的數就可以了 因為大於n的數對答案肯定沒有影響 與bzoj3339完全一樣 似有又水了一題 include include include include include include include include include include defi...

BZOJ 3585 mex 莫隊演算法 分塊

題目大意 給定乙個長度為n的陣列,m次詢問某個區間內的mex值 怒寫莫隊233 將權值分成 n塊,記錄每個權值的出現次數以及每塊內有多少權值出現過 修改o 1 即可完成 查詢時首先掃一遍找到第乙個塊內有沒有覆蓋的點的塊 然後在塊內暴力查詢 時間複雜度o n 套個莫隊 總時間複雜度o m n incl...

bzoj3585 mex 分塊 莫隊演算法

首先,按照莫隊的方式對操作排序,對權值分塊,維護一下每個塊出現的個數。每次詢問,找到第乙個沒有鋪滿的塊,在下乙個塊內暴力找即可。include include include include include include define maxn 200010 using namespace std...