[Explanations] CF1142B Lynyrd Skynyrd (multiplication)

[Explanations] CF1142B Lynyrd Skynyrd (multiplication)

Tune an hour turned out to be read into the read backwards ....

Qiuzi segment sequence routine if there is a permutation of the permutation given arrangement seen, then give the sequence given by this substitution, the problem translates into increased up sequence. This is because a number of predecessor successor is unique.

This title has changed a little bit, we ask for is similar to \ (4 \ quad 5 \ quad1 \ quad 2 \ quad 3 \) sub-sequences. It is equivalent to 1 Tim had a precursor n, to \ (n \) Tim had a successor \ (1 \) , the essence is still the same, still a number of predecessor successor is unique.

When the original 1, m no additional relations, the practice is to locate all \ (1 \) consider a step by step doubling successor to \ (m \) to see the location where. Now 1, m relationship, and on each point can be the starting point. Now it is to maintain a data request interval \ (\ min \) , and with how you write, you can ask offline \ (O (n) \) but I watch the direct st

//@winlere
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;  typedef long long ll;
inline int qr(){
    register int ret=0,f=0;
    register char c=getchar();
    while(!isdigit(c))f|=c==45,c=getchar();
    while(isdigit(c)) ret=ret*10+c-48,c=getchar();
    return f?-ret:ret;
}
const int maxn=2e5+5;
int p[maxn],data[maxn];
int st[19][maxn],Pair[maxn],Min[19][maxn];
int lg[maxn];
int last[maxn];
int n,m,T;
const int inf=0x3f3f3f3f;
int main(){
    /*
#ifndef ONLINE_JUDGE
    freopen("in.in","r",stdin);
    freopen("out.out","w",stdout);
#endif
    */
    m=qr(); n=qr();  T=qr();
    for(int t=2;t<=n;++t) lg[t]=lg[t>>1]+1;
    for(int t=1;t<=m;++t) p[qr()]=t;
    for(int t=1;t<=n;++t) data[t]=p[qr()];
    //for(int t=1;t<=n;++t) cerr<<data[t]<<' ';
    //cerr<<('\n');
    for(int t=n;t;--t){
        if(last[data[t]+1]) st[0][t]=last[data[t]+1];
        if(data[t]==m&&last[1]) st[0][t]=last[1];
        last[data[t]]=t;
    }
    //for(int t=1;t<=n;++t) cerr<<st[0][t]<<' ';
    //cerr<<endl;
    for(int t=1;t<=lg[m];++t)
        for(int i=1;i<=n;++i)
            st[t][i]=st[t-1][st[t-1][i]];
    memset(Min,0x3f,sizeof Min);
    for(int t=1;t<=n;++t){
        int k=t;
        for(int i=0;i<=lg[m-1];++i)
            if(((m-1)>>i&1))
                k=st[i][k];
        if(k) Min[0][t]=k;
    }
    for(int t=1;t<=lg[n];++t)
        for(int i=1;i<=n;++i)
            Min[t][i]=min(Min[t-1][i]?Min[t-1][i]:inf,Min[t-1][i+(1<<t>>1)]?Min[t-1][i+(1<<t>>1)]:inf);
    //for(int t=1;t<=n;++t) cerr<<Min[1][t]<<' ';
    //cerr<<endl;
    while(T--){
        int l=qr(),r=qr();
        //cerr<<"min="<<Min[lg[r-l+1]][l]<<' '<<Min[lg[r-l+1]][r-(1<<lg[r-l+1])+1] <<endl;
        if(min(Min[lg[r-l+1]][l],Min[lg[r-l+1]][r-(1<<lg[r-l+1])+1])<=r) putchar(49);
        else putchar(48);
    }
    putchar(10);
    return 0;
}

Guess you like

Origin www.cnblogs.com/winlere/p/11808997.html
Recommended