QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#787097#8079. Range Periodicity QueryharlemTL 731ms65436kbC++143.5kb2024-11-27 09:42:142024-11-27 09:42:14

Judging History

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

  • [2024-11-27 09:42:14]
  • 评测
  • 测评结果:TL
  • 用时:731ms
  • 内存:65436kb
  • [2024-11-27 09:42:14]
  • 提交

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=5e5+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];
inline 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;
    }
}
inline ll gethash(int l,int r){
    return (hsh[r]-hsh[l-1]*cf[r-l+1]%mod+mod)%mod;
}

inline 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;

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();
    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;
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 44600kb

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: 0
Accepted
time: 731ms
memory: 60388kb

input:

200000
BAbBbBabBBbbABbbaBbaaabaBBAbBbBAAAAABBaBaAAabBAAbABaaBABAabAAAbabbAaBABAbabbAAAbbbbabBBAbbBaabBAAAbBBBbBbbAbbbBabbBABaBAaAAAbBbaABabBAbAAbBbbAbAbBaabAbBBbaaaaBaBbbABBBaaabBaBABAbBabBbbAABBbaBAbaBAbAAABABAbaabbaAAaBAbAbAbBBbaaaAaBaaABBbBAAaAAAaaABbbaAbAaBbaAaaababbaBbaAAAAAAabbBaAabbbaBBAAaABb...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
61006
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 500000 lines

Test #3:

score: 0
Accepted
time: 260ms
memory: 55628kb

input:

10
baaAaAAaAA
500000
6 8 2 3 1 8 7 3 9 4 1 6 9 4 10 10 4 3 1 7 4 3 9 7 1 2 9 3 3 1 10 8 1 6 4 1 6 10 1 5 1 8 9 9 7 3 6 3 9 1 7 6 7 7 9 10 3 2 4 10 7 3 7 1 5 3 5 1 10 1 3 2 2 4 2 3 4 10 5 2 7 10 5 6 8 9 10 6 9 7 5 4 5 4 4 2 5 8 1 9 1 2 10 8 2 5 6 6 6 4 3 1 2 2 3 5 7 4 5 7 5 8 1 8 9 7 6 3 10 7 5 4 8 8...

output:

5
4
4
2
6
3
3
4
6
3
1
6
4
5
3
5
2
5
4
4
2
5
3
5
5
1
2
5
3
5
4
3
5
6
4
5
4
6
4
6
4
1
5
4
4
3
5
3
3
4
5
5
5
4
1
6
5
5
4
4
2
4
3
5
4
5
1
5
1
1
4
4
5
4
4
3
3
4
2
4
4
4
2
4
6
5
2
5
4
3
4
2
4
5
5
4
6
1
2
6
4
5
6
1
1
3
2
3
1
4
4
3
4
4
4
3
6
5
4
5
5
4
1
2
3
4
5
4
4
4
3
6
4
4
4
2
3
3
3
3
3
6
3
5
3
4
6
3
4
5
...

result:

ok 500000 lines

Test #4:

score: 0
Accepted
time: 334ms
memory: 56696kb

input:

500
ababbBbBabaaBAbabBbbBBAAABabBbBAAABbaBbBAAbabaBaAAaabAaABBBabababAAbaaAbbAAabAAbBbaabbBbaAAABaAaBbbBbabBAABBaabbAabbBabbbAbABaBAABaBbAaaBABBbBAAbbbBabbABABAaAaAAAbaAabBbBaaaaAAAAAabaBBAAABAbbabAaBAbAaaBBbABbBBbaaAaAaBBbaBbabBbBABbaaBbAaabBABaBBbAAaaBABBAaaABAbbaaAaBaAAbAbbbbbaabBabaBbaabaAbaBaaa...

output:

386
327
309
141
424
175
186
273
45
498
99
262
478
149
424
444
49
267
233
388
359
310
203
81
498
12
97
295
400
351
352
407
310
471
291
479
448
203
267
60
223
458
421
391
5
470
212
253
99
281
167
451
154
86
299
434
370
255
383
207
258
310
487
380
6
368
235
137
334
141
50
128
29
478
448
223
466
345
407...

result:

ok 500000 lines

Test #5:

score: 0
Accepted
time: 304ms
memory: 64744kb

input:

10000
BaBbAAaaaaBAbbbbbaBbaaAbaaaabAaaaAAbabBAbaaBABaaabaAbBBaBBABAbabBAbaaAAaAABABbbbABBaBBaABbbAAbBabaAbaBBaAbabaaAAAabAbAABAabBbBaBaAaAbbBAAABbbabAaABABaBbaAABBbbBAABbbbAaABaAaaABAbbbABAabbaAaaBbbbBaBBbAaaabbaBbaaAbabBabaBaAAAbBAabbBAbabAAbbBBBbBAAaBBbBBAbaaaAbBaaBAAbbaAbbbBAbaAaaAbBBAaBabBaaaBab...

output:

-1
5219
4322
2614
7302
1876
-1
5584
2861
3586
4821
6579
6706
1605
7878
886
9218
293
167
7298
5146
6860
2921
8263
4330
9578
7472
6086
5537
4890
8285
58
9733
-1
3157
262
9533
6943
8285
2837
451
6494
7918
8912
2187
9832
4487
2077
871
210
951
1761
6892
4304
6634
9572
9544
5744
4015
7418
7804
5928
3611
8...

result:

ok 500000 lines

Test #6:

score: 0
Accepted
time: 511ms
memory: 65436kb

input:

100000
aabAbBbaBAaabbbbbaAAABaaabbBaBAAaBabbBAbBbbBbbbaaaABaaBaBbBABBBbabBAABbabbAaaaBBaAAbABaBABAABbBAbBAAAbaBaabbAAABaBAaaaBBbBbaBabAbBBaaabaaaaBbBaAaAbAbbBaABaabBbBaAAaAaaBbbAbbaaBBbbbaAaAabaBaAaaBaAAbbBabBaBAbAaabAbbbAbaAbBbaABABAaBBABAaABBBBABAaBAbbbaBbaAABBaAabaAbaAaabAAAbbbaBBbBaaaaAaaAABbBaa...

output:

35335
42708
80231
-1
52892
27828
25395
21105
26112
55093
16568
16170
-1
73256
-1
82801
58592
52120
48659
-1
-1
-1
92581
-1
67746
9463
50384
69443
71368
-1
62536
83524
71293
88216
83685
45630
5450
969
3140
19286
79236
80564
33058
44088
24142
-1
40385
68116
-1
20399
78247
52636
37514
-1
54565
44272
75...

result:

ok 500000 lines

Test #7:

score: -100
Time Limit Exceeded

input:

500000
AaAAaaAaaaAaaaaaAaAAAaaaaAAaAAAaaAAAaAaaaaAaAaaaAaAaAAaAAaAaaAaaAaAAAAAAAAAAAAaAaAAAaAaAAAAAaaaAaAAAaAaaaAaaAaaaaaaAaaaaAaAaaAAaAAaaAAAaAaaaaaaaAaAaAaAaaAAaaaAAaAaaAAAaaaaaaaAAaAAaAaaaaaAAaAaAaaAAaaaAAaaaAaAAaaaAaAaaAAAaaAAAaAaaaaaaaaaAaAaAaAAAaaAAAAaAaAAAAAAaAAAaAaaaaaaAAaAaaAAaAAAaaaAaAAaAA...

output:


result: