QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#650313 | #8079. Range Periodicity Query | Shunpower | TL | 0ms | 13804kb | C++14 | 3.2kb | 2024-10-18 14:34:49 | 2024-10-18 14:34:49 |
Judging History
answer
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define rep(i,x,y) for(register int i=x;i<=y;i++)
#define rep1(i,x,y) for(register int i=x;i>=y;--i)
#define int long long
#define fire signed
#define il inline
template<class T> il void print(T x) {
if(x<0) printf("-"),x=-x;
if (x > 9) print(x / 10);
putchar(x % 10 + '0');
}
template<class T> il void in(T &x) {
x = 0; char ch = getchar();
int f = 1;
while (ch < '0' || ch > '9') {if(ch=='-') f = -1; ch = getchar(); }
while (ch >= '0' && ch <= '9') { x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar(); }
x *= f;
}
int T=1;
const int N=5e5+10,mod=1e9+7,ba=131;
deque<char>q;
int ha[N];
int n,l[N],r[N],jc[N];
string now;
int hs(int l,int r) {
return ((ha[r]-ha[l-1]*jc[r-l+1]%mod)%mod+mod)%mod;
}
int m;
struct node{
int k,l,r,id;
friend bool operator<(const node&a,const node&b) {
return a.k>b.k;
}
}s1[N];
struct sgt{
int l,r;
int Max;
}tr[N<<2];
void build(int u,int l,int r) {
tr[u]={l,r};
if(l==r) return ;
int mid=l+r>>1;
build(u<<1,l,mid);
build(u<<1|1,mid+1,r);
}
void up(int x) {
tr[x].Max=max(tr[x<<1].Max,tr[x<<1|1].Max);
}
void modify(int u,int x) {
if(tr[u].l==tr[u].r) {
tr[u].Max=1;
return;
}
int mid=tr[u].l+tr[u].r>>1;
if(mid>=x) modify(u<<1,x);
else modify(u<<1|1,x);
up(u);
}
int Ans(int u,int l,int r) {
if(tr[u].l>=l&&tr[u].r<=r) {
return tr[u].Max;
}
int mid=tr[u].l+tr[u].r>>1,res=0;
if(mid>=l) res=Ans(u<<1,l,r);
if(mid<r) res=max(res,Ans(u<<1|1,l,r));
return res;
}
pair<int,int>lst[N];
void solve() {
in(n);
cin>>now;
int cnt=false;
for(auto to:now) {
++cnt;
if(to>='a'&&to<='z') {
q.push_front(to);
rep(j,1,cnt) l[j]++,r[j]++;
}else q.push_back(to-'A'+'a'),l[cnt]=1,r[cnt]=cnt;
}
// rep(i,1,n) l[i]+=l[i-1],r[i]+=r[i-1];
// rep(i,1,n) cout<<l[i]<<' '<<r[i]<<endl;
jc[0]=1;
rep(i,1,n) jc[i]=jc[i-1]*ba%mod;
int cc=0;
while(q.size()) {
cc++;
ha[cc]=ha[cc-1]*ba%mod+(q.front()-'a'+1)%mod;
q.pop_front();
}
in(m);
rep(i,1,m) {
int p;
in(p);
int ll=p,rr=n,res=0;
while(ll<=rr) {
int mid=ll+rr>>1;
if(hs(l[mid],l[mid]+mid-p-1)==hs(r[mid]-(mid-p)+1,r[mid])) ll=mid+1,res=mid;
else rr=mid-1;
}
lst[i]={res,p};
}
// sort(lst+1,lst+1+m);
// reverse(lst+1,lst+1+m);
int q;
in(q);
rep(i,1,q) {
in(s1[i].k),in(s1[i].l),in(s1[i].r);
int res=INT_MAX;
rep(j,s1[i].l,s1[i].r) {
if(lst[j].first>=s1[i].k) {
res=min(res,lst[j].second);
}
}
if(res>s1[i].k) cout<<"-1\n";
else cout<<res<<endl;
// s1[i].id=i;
}
// sort(s1+1,s1+1+q);
// int l=0;
// build(1,1,n);
// rep(i,1,q) {
// while(lst[l].first>=s1[i].k&&l<=m) {
// modify(1,lst[i].second);
// l++;
// }
// if(Ans(1,s1[i].l,s1[i].r)<=0) ans[s1[i].id]=-1;
// else {
// int l=s1[i].l,r=s1[i].r,res=0;
// while(l<=r) {
// int mid=l+r>>1;
// if(Ans(1,s1[i].l,mid)>=1) res=mid,r=mid-1;
// else l=mid+1;
// }
// }
// }
}
fire main() {
// freopen("period.in","r",stdin);
// freopen("period.out","w",stdout);
while(T--) {
solve();
}
return false;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 13804kb
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...