QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#837638 | #8701. Border | CuFeO4 | 23 | 5ms | 14308kb | C++14 | 3.4kb | 2024-12-30 10:27:50 | 2024-12-30 10:27:50 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t,p) for(int i = s;i <= t;i += p)
#define drep(i,s,t,p) for(int i = s;i >= t;i -= p)
#ifdef LOCAL
auto I = freopen("in.in","r",stdin),O = freopen("out.out","w",stdout);
#else
auto I = stdin,O = stdout;
#endif
using ll = long long;using ull = unsigned long long;
using db = long double;using ldb = long double;
const int N = 2e6 + 10;
const ll base = 2707,mod = 2432021027;
int n,m,ans[N];ll pw[N];
char s[N],t[N];
struct Hash{
ll h[N];int n;
void init(char *s){
n = strlen(s + 1);
rep(i,1,n,1) h[i] = (h[i-1]*base + s[i])%mod;
}
ll get(int l,int r){
return (h[r] - h[l-1]*pw[r-l+1]%mod + mod)%mod;
}
}hs;
set<int> st;
//cbaababaabacbaabadbaababaabacbaabacbaaba
//aabwaxjbbabtalbabcasbabibbabaabbabaabiac
//
void getoriginal(){
drep(len,n,1,1){
if(hs.get(1,len) == hs.get(n-len+1,n)) st.emplace(len);
}
}
struct Segment_Tree{
struct node{
int l,r,len;ll val;
node(){}
node(int L,int R,int N,ll V):l(L),r(R),len(N),val(V){}
#define l(x) t[x].l
#define r(x) t[x].r
#define len(x) t[x].len
#define val(x) t[x].val
}t[N<<2];
ll M(int x,int y){return (val(x)*pw[len(y)]%mod+val(y))%mod;}
node Mg(node x,node y){
return node(x.l,y.r,x.len+y.len,(x.val*pw[y.len]%mod+y.val)%mod);
}
void P(int k){t[k].val = M(k<<1,k<<1|1);}
void B(int k,int l,int r){
l(k) = l,r(k) = r;len(k) = r - l + 1;
if(l == r) return val(k) = s[l],void();
int mid = (l + r) >> 1;
B(k<<1,l,mid);B(k<<1|1,mid+1,r);P(k);
}
void upd(int k,int pos,char x){
if(pos > n) return;
if(l(k) == r(k)) return val(k) = x,void();
int mid = (l(k) + r(k)) >> 1;
pos <= mid?upd(k<<1,pos,x):upd(k<<1|1,pos,x);P(k);
}
node qry(int k,int l,int r){
if(l <= l(k) && r(k) <= r) return t[k];
int mid = (l(k) + r(k)) >> 1;
if(r <= mid) return qry(k<<1,l,r);
if(l > mid) return qry(k<<1|1,l,r);
return Mg(qry(k<<1,l,mid),qry(k<<1|1,mid+1,r));
}
#undef l
#undef r
#undef val
#undef len
}sgt;
signed main(){
cin.tie(nullptr)->sync_with_stdio(false);
cin>>(s+1)>>(t+1);n = strlen(s+1),m = strlen(t+1);
pw[0] = 1;rep(i,1,n,1) pw[i] = pw[i-1]*base%mod;
hs.init(s);sgt.B(1,1,n);
getoriginal();
ans[0] = st.size()?*st.rbegin():0;
rep(i,1,n,1) if(s[i] == t[i]) ans[i] = ans[0];
rep(len,1,n,1){
int l = 1,r = len,p = 0;
//cerr<<"\033[32m";cerr<<len<<":\n";cerr<<"\033[0m";
while(l <= r){
int mid = (l + r) >> 1;
if(hs.get(1,mid) == hs.get(n-len+1,n-len+mid)){
p = mid,l = mid + 1;
}
else r = mid - 1;
}
//if(len == 23) cerr<<"LCP Is : "<<p<<'\n';
//if(len == 23) cerr<<n-len+1+p<<'\n';
//cerr<<'\n';
if(n - len + p + 1 <= n){
sgt.upd(1,n-len+p+1,t[n-len+1+p]);
if(sgt.qry(1,1,len).val == sgt.qry(1,n-len+1,n).val)
ans[n-len+p+1] = len;
sgt.upd(1,n-len+p+1,s[n-len+1+p]);
}
if(p + 1 <= n){
sgt.upd(1,p+1,t[p+1]);
if(sgt.qry(1,1,len).val == sgt.qry(1,n-len+1,n).val) ans[p+1] = len;
sgt.upd(1,p+1,s[p+1]);
}
}
//rep(i,1,n,1) cerr<<ans[i]<<' ';
//cerr<<"\n\n";
//for(auto i:st) cerr<<i<<'\n';
rep(i,1,n,1){
int res = 0;
if(st.size()){
auto it = st.upper_bound(min(i-1,n-i));
if(it != st.begin()) it--,res = *it;
}
cout<<max(ans[i],res)<<'\n';
}
}
詳細信息
Subtask #1:
score: 23
Accepted
Test #1:
score: 23
Accepted
time: 2ms
memory: 11768kb
input:
cbaababaabacbaababaabacbaabacbaababaabacbaaba dabbababbabaabbafabbgbaabfebaabzababbayaabcac
output:
0 0 0 0 0 0 6 6 6 6 6 6 6 6 6 6 6 17 17 17 17 17 17 17 17 17 17 17 6 6 6 6 6 6 6 6 6 6 6 0 0 0 3 0 1
result:
ok 45 numbers
Test #2:
score: 23
Accepted
time: 0ms
memory: 11848kb
input:
cbaababaabacbaabadbaababaabacbaabacbaaba aabwaxjbbabtalbabcasbabibbabaabbabaabiac
output:
3 0 0 0 0 0 6 6 6 6 6 6 6 6 6 6 6 23 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 0 0 0 0 0 1
result:
ok 40 numbers
Test #3:
score: 23
Accepted
time: 0ms
memory: 13820kb
input:
cadaabacabacabacabaabacabacadaabacabacaba bbbbbabtbabababalalbawababababbaoababebdc
output:
2 0 4 0 0 0 0 0 0 0 0 0 0 0 0 15 15 15 15 15 15 15 15 15 15 15 0 0 0 0 0 0 0 0 0 0 0 0 0 4 1
result:
ok 41 numbers
Test #4:
score: 23
Accepted
time: 2ms
memory: 13836kb
input:
dabacbaadcbaadabacbaadabecbaadcbaadabacbaadabacbaa ababaabbyaarbabfbvdbuaoaaaabbaaabbababaabbababqadd
output:
2 0 0 0 0 0 0 0 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 29 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 0 0 0 0 0 0 2 1
result:
ok 50 numbers
Test #5:
score: 23
Accepted
time: 0ms
memory: 13964kb
input:
edacbcacacbcaecbcacacbcadacbcacacbca sabaaabtbaaabaaalblbawaeabaaababoaae
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 13 0 0 0 0 0 0 0 0 0 0 0 1
result:
ok 36 numbers
Test #6:
score: 23
Accepted
time: 0ms
memory: 13892kb
input:
cbaababaabacbaabacbaabdbaabacbaabacbaaba aabbababbaoaabbxbaabbaqabbabltbpagaabcac
output:
3 0 0 0 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 0 0 0 3 0 1
result:
ok 40 numbers
Subtask #2:
score: 0
Wrong Answer
Dependency #1:
100%
Accepted
Test #7:
score: 0
Wrong Answer
time: 5ms
memory: 14308kb
input:
abacadcabbacabbacabcabbacabacabbacabbacabcabbacabbacadcabbacabbacabcabbacabacabbacabbacabcabbacabbacadcabbacabbacabcabbacababacadcabbacabbacabcabbacabacabbacabbacabcabbacabbacadcabbacabbacaecabbacabacabbacabbacabcabbacabbacadcabbacabbacabcabbacababacadcabbacabbacabcabbacabacabbacabbacabcabbacabbacad...
output:
27 0 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75...
result:
wrong answer 3139th numbers differ - expected: '717', found: '4623'
Subtask #3:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%