| Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
|---|---|---|---|---|---|---|---|---|---|
| 39799 | LYLAKIOI | 【BJ】T3 | C++ | 通过 | 100 | 1300 MS | 66576 KB | 2237 | 2026-02-02 14:51:47 |
#include<bits/stdc++.h> #define up(i,l,r) for(int i=(l);i<=(r);++i) #define down(i,l,r) for(int i=(l);i>=(r);--i) #define pi pair<int,int> #define p1 first #define p2 second #define m_p make_pair #define pb push_back #define eb emplace_back using namespace std; typedef long long ll; inline ll read(){ ll x=0;short t=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')t=-1;ch=getchar();} while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar(); return x*t; } const int maxn=1e5+10; int n,q; struct nd{ int l,r; int res;string s; }d[maxn]; vector<pair<int,char> >v[26]; vector<int>id; const int N=1.5e6+10; int rk[N]; void slv(){ string s;cin>>s;int n=s.size();s=" "+s; up(i,1,n)v[s[i]-'a'].eb(i,s[i]);q=read(); up(i,1,q)d[i].l=read(),d[i].r=read(); vector<int>ve;up(i,1,q)ve.eb(d[i].l),ve.eb(d[i].r+1); sort(ve.begin(),ve.end()); up(i,0,25){ up(j,i+1,25){ vector<pair<int,char> >a(v[i].size()+v[j].size()); merge(v[i].begin(),v[i].end(),v[j].begin(),v[j].end(),a.begin()); id.resize(a.size());int lst=-1,cnt=0; up(k,0,(int)a.size()-1){ if(a[k].p2!=lst)lst=a[k].p2,cnt++; id[k]=cnt; } int pos=0; up(k,0,(int)ve.size()-1){ while(pos<a.size()&&a[pos].p1<ve[k])pos++; rk[ve[k]]=pos; } up(k,1,q){ // auto itl=lower_bound(a.begin(),a.end(),m_p(d[k].l,'a'))-a.begin(); // auto itr=upper_bound(a.begin(),a.end(),m_p(d[k].r,'z'))-a.begin()-1; int itl=rk[d[k].l],itr=rk[d[k].r+1]-1; if(itl<=itr&&id[itr]-id[itl]+1>=d[k].res){ int va=id[itr]-id[itl]+1; string t;t.pb(a[itl].p2),t.pb((i+'a')^(j+'a')^a[itl].p2); if(va==d[k].res){ if(t<d[k].s)d[k].s=t; }else d[k].res=va,d[k].s=t; } } } } up(i,1,q)printf("%d %s\n",d[i].res,d[i].s.c_str()); } int main(){ //freopen("seq.in","r",stdin),freopen("seq.out","w",stdout); slv(); return 0; }