QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#339942#7748. Karshilov's Matching Problem IITx_LcyWA 66ms42896kbC++142.0kb2024-02-28 08:38:292024-02-28 08:38:30

Judging History

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

  • [2024-08-25 20:42:18]
  • hack成功,自动添加数据
  • (/hack/789)
  • [2024-02-28 08:38:30]
  • 评测
  • 测评结果:WA
  • 用时:66ms
  • 内存:42896kb
  • [2024-02-28 08:38:29]
  • 提交

answer

//A tree without skin will surely die.
//A man without face is invincible.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mid ((l+r)>>1)
#define lowbit(x) (x&-x)
#define all(x) (x).begin(),(x).end()
#define rep(i,j,k) for (int i=j;i<=k;++i)
#define per(i,j,k) for (int i=j;i>=k;--i)
#define Tim ((double)clock()/CLOCKS_PER_SEC)
int const N=1.5e5+10;
int n,m,w[N],lcp[N],kmp[N],sm[N],qz[N],gz[N],lg[N],st[20][N],ans[N];string s,t;
struct node{int l,r,id;}q[N];
struct Hash_Table{
    #define ull unsigned long long
    int const B=457;
    int hsh[N],bse[N];
    inline void init(string s){
        s=" "+s,hsh[0]=bse[0]=1;
        rep(i,1,n) hsh[i]=hsh[i-1]*B+s[i]-'a'+233;
        rep(i,1,n) bse[i]=bse[i-1]*B;
    }
    inline ull qry(int l,int r){
        return hsh[r]-hsh[l-1]*bse[r-l+1];
    }
}S,T;
inline int qrymax(int l,int r){
    int k=lg[r-l+1];
    return max(st[k][l],st[k][r-(1<<k)+1]);
}
void solve(){
    cin>>n>>m>>s>>t,S.init(s),T.init(t);
    s=" "+s,t=" "+t;
    rep(i,1,n) cin>>w[i],qz[i]=qz[i-1]+w[i];
    rep(i,1,n){
        int l=1,r=n-i+1,ans=0;
        while (l<=r)
            if (S.qry(1,mid)==T.qry(i,i+mid-1)) l=(ans=mid)+1;
            else r=mid-1;
        lcp[i]=ans;
    }
    rep(i,2,n) lg[i]=lg[i>>1]+1;
    rep(i,1,n) st[0][i]=lcp[i]+i-1;
    rep(j,1,19) rep(i,1,n-(1<<j)+1) st[j][i]=max(st[j-1][i],st[j-1][i+(1<<(j-1))]);
    rep(i,1,n) gz[i]=gz[i-1]+qz[lcp[i]];
    int j=0;sm[1]=qz[1];
    rep(i,2,n){
        while (j && s[j+1]!=s[i]) j=kmp[j];
        if (s[j+1]==s[i]) ++j;
        kmp[i]=j;
        sm[i]=sm[i-1]+w[kmp[i]]+w[i];
    }
    while (m--){
        int x,y;cin>>x>>y;
        int l=x,r=y,ans=x-1;
        while (l<=r)
            if (qrymax(l,mid)<=y) l=(ans=mid)+1;
            else r=mid-1;
        cout<<gz[ans]-gz[x-1]+sm[y-ans]<<'\n';
    }
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    int t=1;
    // cin>>t;
    while (t--) solve();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 15864kb

input:

8 5
abbabaab
aababbab
1 2 4 8 16 32 64 128
1 1
2 3
3 5
4 7
1 8

output:

1
3
3
16
38

result:

ok 5 lines

Test #2:

score: 0
Accepted
time: 2ms
memory: 16140kb

input:

15 4
heheheheehhejie
heheheheheheheh
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9
2 3
4 8
2 6
1 15

output:

3
13
13
174

result:

ok 4 lines

Test #3:

score: -100
Wrong Answer
time: 66ms
memory: 42896kb

input:

150000 150000
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

108146956859578
221439667010807
454936485688890
439882876384069
147712425867485
88490561697623
350907731992678
58849654791050
65421112783253
270109802073950
197623179784696
297729813859831
239502287503773
27735832192573
407976849796475
267643641851435
32013799147213
104410226189923
43659185354937
76...

result:

wrong answer 1st lines differ - expected: '108147037823514', found: '108146956859578'