Konjac boring one

A very simple practice hand topic?
Https://loj.ac/problem/10121#submit_code
subject to the effect:
repeatedly asked perfect sequence interval; (defined as the perfect sequence for a continuous sequence of individual numbers are different)
seeking more intervals most long perfect sequence (without modification)
analysis:
static query: last array, to do the most? dp array
(dynamic queries team estimated it would MO)
Last [a [i]] indicates the position of the first occurrence of the number a [i] of
dp [i] represents the start to the end of the i-th bit of the longest sequence of perfect max position
have: dp [i] = max ( dp [i-1], last [a [i]] + 1) !!!!!!!!!!!!!!!!!!!! this array is the key !!!!!!!!!!!!!!! dp
last query table with pre-st (i-dp [i] +1 ) is the length of each sequence
since the last array increases monotonically , so with half period of the preceding paragraph can be solved not within the range of the interval
can not hand half is not, hard to control the boundaries of the
code by wzxbeliever

#include<bits/stdc++.h>
#define ll long long
#define lowbit(x) x&(-x)
#define il inline
#define ri register int
using namespace std;
const int maxn=2e5+5;
const int maxx=1e6;
int lg[maxn],last[(maxx<<1)+5],st[maxn][20],s[maxn],f[maxn];
int n,m;
il void init(){
    lg[0]=-1;
    for(ri i=1;i<=n;i++)lg[i]=lg[i>>1]+1;
    for(ri j=1;(1<<j)<=n;j++)
    for(ri i=1;i+(1<<j)-1<=n;i++)
    st[i][j]=max(st[i][j-1],st[i+(1<<j-1)][j-1]);
    return;
} 
il int askmax(int L,int R){
    if(L>R)return 0;
    int k=lg[R-L+1];
    return max(st[L][k],st[R-(1<<k)+1][k]);
}
int main(){ 
    scanf("%d%d",&n,&m);
    for(ri i=1,x;i<=n;i++){
        scanf("%d",&x);
    s[i]=max(s[i-1],last[x+maxx]+1);
    f[i]=i-s[i]+1;
    st[i][0]=f[i];
    last[x+maxx]=i;
    }
    init();
    for(ri i=1,L,R;i<=m;i++){
        scanf("%d%d",&L,&R);L++,R++;
        int pos=lower_bound(s+1+L,s+1+R,L)-s-1;
        //cout<<"pos="<<pos<<endl;
       printf("%d\n",max(pos-L+1,askmax(pos+1,R)));
    } 
   return 0;
}

Guess you like

Origin www.cnblogs.com/wzxbeliever/p/12198953.html