Codeforces Round #549 (Div. 2) E. Lynyrd Skynyrd

Link
Multiplication: The next point that the current point is looking for is fixed, use the multiplication speed to
pay attention to the initialization and traversal sequence

#include<bits/stdc++.h>
#define ls rt<<1
#define rs rt<<1|1
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const  ll inf  = 0x3f3f3f3f3f3f3f3f;
const int mod  = 998244353;
const int maxn = 1e6 + 4;
const int N    = 5e3 + 5;
const double eps = 1e-6;
const double pi = acos(-1.0);
ll qpow(ll x,ll y,ll mod){
    
    ll ans=1;x%=mod;while(y){
    
     if(y&1) ans=ans*x%mod; x=x*x%mod; y>>=1;}return ans;}
    
int n,m,q,a[maxn],b[maxn],to[maxn],f[maxn][20],lst[maxn],mr[maxn];
    
int main() {
    
    
    //freopen("RACE input.in","r",stdin);
    scanf("%d%d%d",&n,&m,&q);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    for(int i=1;i<=m;i++) scanf("%d",&b[i]);
    for(int i=1;i<=n;i++) to[a[i]]=a[i+1];
    to[a[n]]=a[1];
    for(int i=1;i<=n;i++) lst[i]=m+1;
    f[m+1][0]=m+1;
    for(int i=m;i>=1;i--) {
    
    
        f[i][0]=lst[to[b[i]]];
        lst[b[i]]=i;
    }
    for(int j=1;j<=19;j++) {
    
    
         for(int i=1;i<=m+1;i++) f[i][j]=f[f[i][j-1]][j-1];
    }//cout<<1<<endl;
    for(int i=1;i<=m;i++) {
    
    
        int x=n-1,r=i;
        for(int j=19;j>=0;j--) if(x>=(1<<j)) x-=(1<<j),r=f[r][j];
        mr[i]=r;
    }
    for(int i=m-1;i>=1;i--) mr[i]=min(mr[i],mr[i+1]);
    //for(int i=1;i<=m;i++) printf("%d ",mr[i]);printf("\n");
    for(int i=1;i<=q;i++) {
    
    
        int l,r;scanf("%d%d",&l,&r);
        if(r>=mr[l]) printf("1");
        else printf("0");
    }
}   

Guess you like

Origin blog.csdn.net/qq_43914084/article/details/106788045