QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#837642#8701. BorderCuFeO423 4ms14112kbC++143.2kb2024-12-30 10:32:022024-12-30 10:32:03

Judging History

你现在查看的是最新测评结果

  • [2024-12-30 10:32:03]
  • 评测
  • 测评结果:23
  • 用时:4ms
  • 内存:14112kb
  • [2024-12-30 10:32:02]
  • 提交

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 ull base = 2707,mod = 2432021027;
int n,m,ans[N];ull pw[N];
char s[N],t[N];
struct Hash{
  ull 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];
  }
  ull get(int l,int r){return h[r] - h[l-1]*pw[r-l+1];}
}hs;
set<int> st;
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;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];
  ull M(int x,int y){return val(x)*pw[len(y)]+val(y);}
  node Mg(node x,node y){
    return node(x.l,y.r,x.len+y.len,x.val*pw[y.len]+y.val);
  }
  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;
  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';
  }
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 23
Accepted

Test #1:

score: 23
Accepted
time: 0ms
memory: 13940kb

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: 13840kb

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: 13804kb

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: 0ms
memory: 13948kb

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: 2ms
memory: 13876kb

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: 13808kb

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: 4ms
memory: 14112kb

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%