可惜没如果=_=
时光的河入海流

 

3339: Rmq Problem

Time Limit: 20 Sec  Memory Limit: 128 MB
Submit: 1362  Solved: 721
[Submit][Status][Discuss]

Description

Input

Output

Sample Input

7 5
0 2 1 0 1 3 2
1 3
2 3
1 4
3 6
2 7

Sample Output

3
0
3
2
4

HINT

 

 

Source

By Xhr

 

3585: mex

Time Limit: 20 Sec  Memory Limit: 128 MB
Submit: 1198  Solved: 615
[Submit][Status][Discuss]

Description

  有一个长度为n的数组{a1,a2,...,an}。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 佚名提供

 

哈哈哈竟然BZOJ上有两道一模一样的题哈哈哈哈哈 可惜是两道权限题(⊙_⊙)

 1 #include "bits/stdc++.h"
 2 using namespace std;
 3 typedef long long LL;
 4 const int MAX=2e5+5;
 5 int n,m;
 6 int a[MAX],b[MAX],pos[MAX],an[MAX],bas,ans;
 7 struct Node{
 8     int id;
 9     int l,r;
10     bool operator < (const Node &tt) const {
11         if (pos[l]!=pos[tt.l])
12             return pos[l]<pos[tt.l];
13         return r<tt.r;
14     }
15 }que[MAX];
16 inline int read(){
17     int an=0,x=1;char c=getchar();
18     while (c<'0' || c>'9') {if (c=='-') x=-1;c=getchar();}
19     while (c>='0' && c<='9') {an=an*10+c-'0';c=getchar();}
20     return an*x;
21 }
22 void update(int x,int y){
23     if (a[x]>n) return;
24     b[a[x]]+=y;
25     if (!b[a[x]]){
26         if (a[x]<ans)
27             ans=a[x];
28     }
29     else if (a[x]==ans){
30         while (b[ans]) ans++;
31     }
32 }
33 int main(){
34     freopen ("mex.in","r",stdin);
35     freopen ("mex.out","w",stdout);
36     int i,j;
37     n=read();m=read();bas=(int)sqrt(n*1.0);
38     for (i=1;i<=n;i++) a[i]=read(),pos[i]=i/bas;
39     memset(b,0,sizeof(b));
40     for (i=1;i<=m;i++){
41         que[i].id=i;
42         que[i].l=read(),que[i].r=read();
43     }
44     sort(que+1,que+m+1);
45     int L=1,R=0;
46     for (i=1;i<=m;i++){
47         while (R<que[i].r) update(++R,1);
48         while (L>que[i].l) update(--L,1);
49         while (R>que[i].r) update(R--,-1);
50         while (L<que[i].l) update(L++,-1);
51         an[que[i].id]=ans;
52     }
53     for (i=1;i<=m;i++)
54         printf("%d\n",an[i]);
55     return 0;
56 }

 

posted on 2017-10-17 09:29  珍珠鸟  阅读(232)  评论(0编辑  收藏  举报