QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#837662 | #8701. Border | CuFeO4 | 0 | 0ms | 15856kb | C++14 | 4.5kb | 2024-12-30 11:02:31 | 2024-12-30 11:02:32 |
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)
namespace IO{
#ifdef LOCAL
FILE*Fin(fopen("in.in","r")),*Fout(fopen("out.out","w"));
#else
FILE*Fin(stdin),*Fout(stdout);
#endif
class qistream{static const size_t SIZE=1<<26,BLOCK=64;FILE*fp;char buf[SIZE];int p;public:qistream(FILE*_fp=stdin):fp(_fp),p(0){fread_unlocked(buf+p,1,SIZE-p,fp);}void flush(){memmove(buf,buf+p,SIZE-p),fread_unlocked(buf+SIZE-p,1,p,fp),p=0;}qistream&operator>>(char&str){str=getch();while(isspace(str))str=getch();return*this;}template<class T>qistream&operator>>(T&x){x=0;p+BLOCK>=SIZE?flush():void();bool flag=false;for(;!isdigit(buf[p]);++p)flag=buf[p]=='-';for(;isdigit(buf[p]);++p)x=x*10+buf[p]-'0';x=flag?-x:x;return*this;}char getch(){return buf[p++];}qistream&operator>>(char*str){char ch=getch();while(ch<=' ')ch=getch();for(int i=0;ch>' ';++i,ch=getch())str[i]=ch;return*this;}}qcin(Fin);
class qostream{static const size_t SIZE=1<<26,BLOCK=64;FILE*fp;char buf[SIZE];int p;public:qostream(FILE*_fp=stdout):fp(_fp),p(0){}~qostream(){fwrite_unlocked(buf,1,p,fp);}void flush(){fwrite_unlocked(buf,1,p,fp),p=0;}template<class T>qostream&operator<<(T x){int len=0;p+BLOCK>=SIZE?flush():void();x<0?(x=-x,buf[p++]='-'):0;do buf[p+len]=x%10+'0',x/=10,++len;while(x);for(int i=0,j=len-1;i<j;++i,--j)swap(buf[p+i],buf[p+j]);p+=len;return*this;}qostream&operator<<(char x){putch(x);return*this;}void putch(char ch){p+BLOCK>=SIZE?flush():void();buf[p++]=ch;}qostream&operator<<(char*str){for(int i=0;str[i];++i)putch(str[i]);return*this;}}qcout(Fout);
}using namespace IO;
#define cin qcin
#define cout qcout
using ll = long long;using ull = unsigned long long;
using db = long double;using ldb = long double;
const int N = 2e6 + 10;
const ull base = 2707;
int n,m,ans[N];ull pw[N];
char s[N],t[N];
struct Hash{
ull h[N];int n;
inline void init(char *s,int len){
n = len;
rep(i,1,n,1) h[i] = h[i-1]*base + s[i];
}
inline ull get(int l,int r){return h[r] - h[l-1]*pw[r-l+1];}
}hs;
vector<int> st;
inline void getoriginal(){
rep(len,1,n-1,1) if(hs.get(1,len) == hs.get(n-len+1,n)) st.emplace_back(len);
}
struct Segment_Tree{
struct node{
int l,r,len;ull val;
node(){}
node(int L,int R,int N,ull 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];
inline ull M(int x,int y){return val(x)*pw[len(y)]+val(y);}
struct Qn{int len;ull val;Qn(int L,ull V){len = L,val = V;}};
inline Qn Mg(Qn x,Qn y){return Qn(x.len + y.len,x.val*pw[y.len] + y.val);}
inline 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(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);
}
Qn qry(int k,int l,int r){
if(l <= l(k) && r(k) <= r) return Qn(t[k].len,t[k].val);
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);
pw[0] = 1;rep(i,1,n,1) pw[i] = pw[i-1]*base;
hs.init(s,n);sgt.B(1,1,n);
getoriginal();
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;
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;
}
int r1 = n - len + p + 1;
int r2 = p + 1;
if(r1 <= n){
sgt.upd(1,r1,t[n-len+1+p]);
if(sgt.qry(1,1,len).val == sgt.qry(1,n-len+1,n).val)
ans[r1] = max(len,ans[r1]);
sgt.upd(1,r1,s[n-len+1+p]);
}
if(r2 <= n){
sgt.upd(1,r2,t[r2]);
if(sgt.qry(1,1,len).val == sgt.qry(1,n-len+1,n).val)
ans[r2] = max(len,ans[r2]);
sgt.upd(1,r2,s[r2]);
}
}
rep(i,1,n,1){
int res = 0;
if(s[i] != t[i] && st.size()){
auto it = upper_bound(st.begin(),st.end(),min(i-1,n-i));
it++;
if(it != st.begin()) res = *it;
}
cout<<max(ans[i],res)<<'\n';
}
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 15856kb
input:
cbaababaabacbaababaabacbaabacbaababaabacbaaba dabbababbabaabbafabbgbaabfebaabzababbayaabcac
output:
17 17 17 17 17 17 6 0 0 0 0 0 0 0 0 0 0 17 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 17 17 17 17 17 17
result:
wrong answer 1st numbers differ - expected: '0', found: '17'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%