QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#787094#8079. Range Periodicity QueryharlemRE 0ms11852kbC++143.6kb2024-11-27 09:39:202024-11-27 09:39:20

Judging History

你现在查看的是最新测评结果

  • [2024-11-27 09:39:20]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:11852kb
  • [2024-11-27 09:39:20]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef __int128 i128;
typedef double db;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
template <typename Type>
using vec=vector<Type>;
template <typename Type>
using grheap=priority_queue<Type>;
template <typename Type>
using lrheap=priority_queue<Type,vector<Type>,greater<Type> >;
#define fir first
#define sec second
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define rep(i,x,y) for(int i=x;i<=y;i++)
#define per(i,x,y) for(int i=x;i>=y;i--)

const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7/*998244353*/;
const ll bas=131;

const int N=1e5+5;

int n,m,q;
char c[N];
string s;
int ls[N],rs[N];
int p[N],ts[N],tp[N];
vec<int> plc[N],ned[N];
int arr[N];
struct query{
    int k,l,r;
}qs[N];
int ans[N];

ll hsh[N],cf[N];
void hinit(){
    cf[0]=1;
    rep(i,1,n){
        hsh[i]=(hsh[i-1]*bas%mod+s[i])%mod;
        cf[i]=cf[i-1]*bas%mod;
    }
}
ll gethash(int l,int r){
    return (hsh[r]-hsh[l-1]*cf[r-l+1]%mod+mod)%mod;
}

int finds(int x){
    int l=x,r=n;
    while(l<r){
        int m=l+r+1>>1;
        int len=m-x;
        if(gethash(ls[m],ls[m]+len-1)==gethash(rs[m]-len+1,rs[m]))l=m;
        else r=m-1;
    }
    return l;
}

struct segment{
    int dat[N*4];
    void update(int x){
        dat[x]=min(dat[x*2],dat[x*2+1]);
    }
    void build(int x=1,int l=1,int r=m){
        dat[x]=inf;
        if(l==r)return;
        int m=l+r>>1;
        build(x*2,l,m);
        build(x*2+1,m+1,r);
        update(x);
    }
    void chg(int k,int v,int x=1,int l=1,int r=m){
        if(l==r){
            dat[x]=v;
            return;
        }
        int m=l+r>>1;
        if(k<=m)chg(k,v,x*2,l,m);
        else chg(k,v,x*2+1,m+1,r);
        update(x);
    }
    int query(int lq,int rq,int x=1,int l=1,int r=m){
        if(lq<=l&&r<=rq){
            return dat[x];
        }
        int m=l+r>>1,res=inf;
        if(lq<=m)chmin(res,query(lq,rq,x*2,l,m));
        if(m<rq)chmin(res,query(lq,rq,x*2+1,m+1,r));
        return res;
    }
}seg;

void dbg(){
    rep(i,1,n)cout<<s[i];
    cout<<"\n";
    cout<<gethash(1,3)<<" "<<gethash(4,6)<<"\n";
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>n;
    int fst;
    rep(i,1,n){
        cin>>c[i];
        if(i==1)fst=1,s=(char)tolower(c[i]);
        else{
            if(islower(c[i])!=0){
                s=c[i]+s;
                fst++;
            }else s=s+(char)tolower(c[i]);
        }
    }
    ls[1]=rs[1]=fst;
    rep(i,2,n){
        ls[i]=ls[i-1];rs[i]=rs[i-1];
        if(islower(c[i])!=0)ls[i]--;
        else rs[i]++;
    }
    s=' '+s;
    hinit();
    // dbg();
    rep(i,1,n)ts[i]=finds(i),arr[i]=i;
    sort(arr+1,arr+1+n,[](int a,int b){return ts[a]<ts[b];});
    cin>>m;
    rep(i,1,m){
        cin>>p[i];
        plc[p[i]].pub(i);
    }
    cin>>q;
    rep(i,1,q){
        cin>>qs[i].k>>qs[i].l>>qs[i].r;
        ned[qs[i].k].pub(i);
    }
    seg.build();
    int j=n;
    per(i,n,1){
        while(j>=1&&ts[arr[j]]>=i){
            for(auto p:plc[arr[j]])seg.chg(p,arr[j]);
            j--;
        }
        for(auto q:ned[i]){
            int res=seg.query(qs[q].l,qs[q].r);
            if(res>i)res=-1;
            ans[q]=res;
        }
    }
    rep(i,1,q)cout<<ans[i]<<"\n";
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 11852kb

input:

7
AABAAba
9
4 3 2 1 7 5 3 6 1
6
1 4 4
2 1 4
2 1 3
3 3 5
5 4 7
7 8 9

output:

1
1
2
-1
3
6

result:

ok 6 lines

Test #2:

score: -100
Runtime Error

input:

200000
BAbBbBabBBbbABbbaBbaaabaBBAbBbBAAAAABBaBaAAabBAAbABaaBABAabAAAbabbAaBABAbabbAAAbbbbabBBAbbBaabBAAAbBBBbBbbAbbbBabbBABaBAaAAAbBbaABabBAbAAbBbbAbAbBaabAbBBbaaaaBaBbbABBBaaabBaBABAbBabBbbAABBbaBAbaBAbAAABABAbaabbaAAaBAbAbAbBBbaaaAaBaaABBbBAAaAAAaaABbbaAbAaBbaAaaababbaBbaAAAAAAabbBaAabbbaBBAAaABb...

output:


result: