QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#650003 | #8079. Range Periodicity Query | S00021 | WA | 692ms | 78640kb | C++14 | 2.5kb | 2024-10-18 12:11:47 | 2024-10-18 12:11:52 |
Judging History
answer
#include<bits/stdc++.h>
#define N 500005
#define P1 131
#define I 1ll
#define P2 191
#define INF 0x3f3f3f3f
#define M 998244353
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define MP make_pair
#define ull unsigned long long
#define pui pair<ull,int>
#define INF 0x3f3f3f3f
using namespace std;
struct SGT{
#define ls (rt<<1)
#define rs (rt<<1|1)
int T[N<<3];
void build(int rt,int l,int r){ T[rt]=INF;
if(l==r) return; int md=(l+r)>>1;
build(ls,l,md),build(rs,md+1,r);
}void modf(int rt,int l,int r,int x,int d){
if(l==r){T[rt]=d; return;} int md=(l+r)>>1;
if(x<=md) modf(ls,l,md,x,d);
else modf(rs,md+1,r,x,d); T[rt]=min(T[ls],T[rs]);
}int ask(int rt,int l,int r,int L,int R){
if(L<=l&&r<=R) return T[rt]; int md=(l+r)>>1,ret=INF;
if(L<=md) ret=min(ret,ask(ls,l,md,L,R));
if(R>md) ret=min(ret,ask(rs,md+1,r,L,R)); return ret; }
}T;
ull pw1[N]; int rpos[N];
int n,m,Q,ans[N],L[N],R[N],p[N],pw2[N],hd,tl,q0[N];
char s[N]; pui h[N];
vector<array<int,3>> qr[N];
vector<int> pos[N];
void init(){ pw1[0]=pw2[0]=1;
for(int i=1;i<=n;i++)
pw1[i]=pw1[i-1]*P1,pw2[i]=I*pw2[i-1]*P2%M;
hd=n+1,tl=n;
for(int i=1;i<=n;i++){
if(s[i]>='A'&&s[i]<='Z') q0[++tl]=s[i]-'A'+1;
if(s[i]>='a'&&s[i]<='z') q0[--hd]=s[i]-'a'+1;
L[i]=hd,R[i]=tl;
}for(int i=hd;i<=tl;i++){
h[i].fi=h[i-1].fi*P1+q0[i];
h[i].se=(I*h[i-1].se*P2%M+q0[i])%M; }
}pui ask(int l,int r){
return MP(h[r].fi-h[l-1].fi*pw1[r-l+1],(h[r].se+M-I*h[l-1].se*pw2[r-l+1]%M)%M);
}bool eq(pui x,pui y){return x.fi==y.fi&&x.se==y.se;}
bool chk(int i,int l){ l=(R[i]-L[i]+1)-l;
return eq(ask(L[i],L[i]+l-1),ask(R[i]-l+1,R[i]));
}int id[N];
bool cmp(int x,int y){return rpos[x]>rpos[y];}
signed main(){
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
scanf("%d%s%d",&n,s+1,&m);
for(int i=1;i<=m;i++)
scanf("%d",&p[i]),pos[p[i]].pb(i);
init();
for(int i=1;i<=n;i++){
int l=i,r=n,ret=i;
while(l<=r){
int md=(l+r)>>1;
if(chk(md,i)) l=md+1,ret=md;
else r=md-1; }
rpos[i]=ret; id[i]=i;
}sort(id+1,id+n+1,cmp);
scanf("%d",&Q);
for(int i=1,k,l,r;i<=Q;i++){
scanf("%d%d%d",&k,&l,&r);
qr[k].pb({l,r,i});
}T.build(1,1,m);
for(int i=n,j=1;i;i--){
while(j&&rpos[id[j]]>=i){
for(int u:pos[id[j]]) T.modf(1,1,m,u,p[u]);
j++; }
for(auto u:qr[i]){
ans[u[2]]=T.ask(1,1,m,u[0],u[1]);
if(ans[u[2]]>i) ans[u[2]]=-1;
}
}for(int i=1;i<=Q;i++) printf("%d\n",ans[i]);
return 0;
}/*
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
*/
详细
Test #1:
score: 100
Accepted
time: 4ms
memory: 46880kb
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: 313ms
memory: 50304kb
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: 297ms
memory: 59220kb
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: 374ms
memory: 61228kb
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: 391ms
memory: 62764kb
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: 520ms
memory: 69860kb
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
Wrong Answer
time: 692ms
memory: 78640kb
input:
500000 AaAAaaAaaaAaaaaaAaAAAaaaaAAaAAAaaAAAaAaaaaAaAaaaAaAaAAaAAaAaaAaaAaAAAAAAAAAAAAaAaAAAaAaAAAAAaaaAaAAAaAaaaAaaAaaaaaaAaaaaAaAaaAAaAAaaAAAaAaaaaaaaAaAaAaAaaAAaaaAAaAaaAAAaaaaaaaAAaAAaAaaaaaAAaAaAaaAAaaaAAaaaAaAAaaaAaAaaAAAaaAAAaAaaaaaaaaaAaAaAaAAAaaAAAAaAaAAAAAAaAAAaAaaaaaaAAaAaaAAaAAAaaaAaAAaAA...
output:
243806 -1 -1 -1 292615 -1 -1 43384 255164 -1 -1 -1 -1 -1 -1 -1 -1 230079 -1 -1 -1 210028 -1 -1 93192 -1 -1 -1 -1 -1 -1 -1 281276 -1 494439 264308 207979 -1 -1 -1 -1 -1 -1 -1 -1 394555 -1 294865 -1 -1 -1 -1 -1 407843 -1 378537 -1 134129 122684 -1 -1 -1 -1 -1 -1 142146 -1 -1 11972 -1 -1 -1 -1 -1 -1 -1...
result:
wrong answer 1st lines differ - expected: '3', found: '243806'