QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#650310 | #8079. Range Periodicity Query | harlem | TL | 4ms | 32476kb | C++14 | 2.1kb | 2024-10-18 14:33:54 | 2024-10-18 14:33:54 |
Judging History
answer
//优化不动了
#include<bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef pair<int,pii> pip;
typedef vector<int> veci;
typedef vector<pii> vecp;
typedef priority_queue<int> bghp;
typedef priority_queue<int,vector<int>,greater<int> > lthp;
const int N=5e5+5;
int n,m,q;
char d[N];
veci ld[N];
string s[N];
int p[N];
bool check(int k,int w){
if(w>s[k].size())return false;
for(auto lw:ld[k]){
if(w%lw==0)return true;
}
return false;
}
void bl(int k,int l,int r){
int res=INT_MAX;
for(int i=l;i<=r;i++){
if(check(k,p[i]))res=min(res,p[i]);
}
if(res==INT_MAX)cout<<-1<<"\n";
else cout<<res<<"\n";
}
void br(int k,int l,int r){
bool pd=false;
while(l<r){
int m=l+r>>1;
if(check(k,m))r=m,pd=true;
else l=m+1;
}
if(!pd)cout<<-1<<"\n";
else cout<<l<<"\n";
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin>>n;
ld[0].push_back(0);
for(int i=1;i<=n;i++){
cin>>d[i];
if('a'<=d[i]){
s[i]=d[i]+s[i-1];
for(int j=0;j<ld[i-1].size();j++){
int w=ld[i-1][j];
if(w==0)continue;
if(s[i][0]==s[i][w-1]){
ld[i].push_back(w);
}
}
ld[i].push_back(i);
}
else{
d[i]=d[i]-'A'+'a';
s[i]=s[i-1]+d[i];
for(int j=0;j<ld[i-1].size();j++){
int w=ld[i-1][j];
if(w==0)continue;
if(s[i][i-1-w]==s[i][i-1]){
ld[i].push_back(w);
}
}
ld[i].push_back(i);
}
}
cin>>m;
for(int i=1;i<=m;i++){
cin>>p[i];
}
cin>>q;
int k,l,r;
while(q--){
cin>>k>>l>>r;
if(r-l<=100)bl(k,l,r);
else br(k,l,r);
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 4ms
memory: 32476kb
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
Time Limit Exceeded
input:
200000 BAbBbBabBBbbABbbaBbaaabaBBAbBbBAAAAABBaBaAAabBAAbABaaBABAabAAAbabbAaBABAbabbAAAbbbbabBBAbbBaabBAAAbBBBbBbbAbbbBabbBABaBAaAAAbBbaABabBAbAAbBbbAbAbBaabAbBBbaaaaBaBbbABBBaaabBaBABAbBabBbbAABBbaBAbaBAbAAABABAbaabbaAAaBAbAbAbBBbaaaAaBaaABBbBAAaAAAaaABbbaAbAaBbaAaaababbaBbaAAAAAAabbBaAabbbaBBAAaABb...