提交记录 9131


用户 题目 状态 得分 用时 内存 语言 代码长度
beretty noi18c. 【NOI2018】你的名字 Accepted 100 827.258 ms 416776 KB C++11 4.31 KB
提交时间 评测时间
2019-04-14 14:57:38 2020-08-01 01:33:04
// luogu-judger-enable-o2
#include<cstdio>
#include<cstring>
#include<algorithm>
# define LL long long 
const int M = 1000005 ;
using namespace std ;

inline int read() {
    char c = getchar() ; int x = 0 , w = 1 ;
    while(c>'9'||c<'0') { if(c=='-') w = -1 ; c = getchar() ; }
    while(c>='0'&&c<='9') { x = x*10+c-'0' ; c = getchar() ; }
    return x*w ;
}
char s[M] ;
int n , m , b[M] , pos[M] ;
int c[M] , val[M] , tot , rt[M] , idl , idr ;

struct Suffix {
    int Last , cnt , size[M] ;
    int fa[M] , st[M] , son[M][26] ;
    inline void Init() {
        for(int i = 1 ; i <= cnt ; i ++) {
            for(int j = 0 ; j < 26 ; j ++)  son[i][j] = 0 ;
            size[i] = fa[i] = st[i] = pos[i] = val[i] = 0 ;
        }
        Last = cnt = 1 ;
    }
    inline void Insert(int c) {
        int p = Last , np = ++ cnt ; 
        Last = np ; st[np] = st[p] + 1 ; size[np] = 1 ;
        while(p && !son[p][c]) son[p][c] = np , p = fa[p] ;
        if(!p) fa[np] = 1 ;
        else {
            int q = son[p][c] ;
            if(st[q] == st[p] + 1) fa[np] = q ;
            else {
                int nq = ++ cnt ; st[nq] = st[p] + 1 ;
                memcpy(son[nq] , son[q] , sizeof(son[q])) ;
                fa[nq] = fa[q] ; fa[np] = fa[q] = nq ;
                while(son[p][c] == q) son[p][c] = nq , p = fa[p] ;
            }
        }
    }
    inline void Sort() {
        for(int i = 1 ; i <= cnt ; i ++) ++ c[st[i]] ;
        for(int i = 2 ; i <= cnt ; i ++) c[i] += c[i - 1] ;
        for(int i = 1 ; i <= cnt ; i ++) b[c[st[i]] --] = i ;
        for(int i = cnt , p ; i >= 1 ; i --) {
            p = b[i] ;
            if(!pos[fa[p]]) pos[fa[p]] = pos[p] ;
            else pos[fa[p]] = min(pos[fa[p]] , pos[p]) ;
        }
        for(int i = 1 ; i <= cnt ; i ++) c[i] = b[i] = 0 ;
    }
} S1 , S2 ;

namespace F_Tree {
    # define ls t[now].l
    # define rs t[now].r
    struct Node { int l , r , size ; } t[M * 25] ;
    void Build(int x , int l , int r , int &now) {
        if(!now) now = ++ tot ; t[now].size ++ ;
        if(l == r) return ; int mid = (l + r) >> 1 ;
        if(mid >= x) Build(x , l , mid , ls) ; else Build(x , mid + 1 , r , rs) ;
    }
    int Merge(int x , int y , int l , int r) {
        if(!x || !y) return x + y ; int ecnt = ++ tot ;
        t[ecnt].size = t[x].size + t[y].size ; 
        if(l == r) return ecnt ; int mid = (l + r) >> 1 ; 
        t[ecnt].l = Merge(t[x].l , t[y].l , l , mid) ; 
        t[ecnt].r = Merge(t[x].r , t[y].r , mid + 1 , r) ;
        return ecnt ;
    }
    int query(int L , int R , int l , int r , int now) {
        if(!now || l > R || r < L) return 0 ; 
        if(l == L && r == R) return t[now].size ;
        int mid = (l + r) >> 1 ;
        if(mid >= R) return query(L , R , l , mid , ls) ;
        if(mid < L) return query(L , R , mid + 1 , r , rs) ;
        else return query(L , mid , l , mid , ls) + query(mid + 1 , R , mid + 1 , r , rs) ;
    }
    # undef ls
    # undef rs
}
using namespace F_Tree ;
inline LL Solve() {
    LL Ans = 0 ; int temp = 0 , p = 1 ;
    for(int i = 1 , c ; i <= m ; i ++) {
        c = s[i] - 'a' ;
        while(1) {
        	if(S1.son[p][c] && query(idl + temp , idr , 1 , n , rt[S1.son[p][c]])) {
        		p = S1.son[p][c] ;
        		++ temp ; break ;
            }
            if(!temp) { p = 1 ; break ; }
            -- temp ;
            if(temp == S1.st[S1.fa[p]]) p = S1.fa[p] ;
        }
        val[i] = temp ;
    }
    S2.Sort() ;
    for(int i = 2 ; i <= S2.cnt ; i ++)
        Ans += max(S2.st[i] - max(S2.st[S2.fa[i]] , val[pos[i]]) , 0) ;
    return Ans ;
}
int main() {
    scanf("%s",s + 1) ; n = strlen(s + 1) ; S1.Init() ; 
    for(int i = 1 ; i <= n ; i ++) {
        S1.Insert(s[i] - 'a') ;
        Build(i , 1 , n , rt[S1.Last]) ;
    }
    for(int i = 1 ; i <= S1.cnt ; i ++) ++c[S1.st[i]] ;
    for(int i = 2 ; i <= S1.cnt ; i ++) c[i] += c[i - 1] ;
    for(int i = 1 ; i <= S1.cnt ; i ++) b[c[S1.st[i]] --] = i ;
    for(int i = S1.cnt , p ; i >= 1 ; i --) {
        p = b[i] ;
        if(S1.fa[p]) rt[S1.fa[p]] = Merge(rt[S1.fa[p]] , rt[p] , 1 , n) ;
    }
    memset(c , 0 , sizeof(c)) ;
    int Q = read() ;
    while(Q --) {
        scanf("%s",s + 1) ; m = strlen(s + 1) ; idl = read() ; idr = read() ;
        S2.Init() ; for(int i = 1 ; i <= m ; i ++) S2.Insert(s[i] - 'a') , pos[S2.Last] = i ;
        printf("%lld\n",Solve()) ;
    }
    return 0 ;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #13.419 ms3 MB + 1020 KBAcceptedScore: 4

Testcase #24.13 ms4 MB + 344 KBAcceptedScore: 4

Testcase #34.296 ms4 MB + 348 KBAcceptedScore: 4

Testcase #448.121 ms4 MB + 816 KBAcceptedScore: 4

Testcase #546.312 ms4 MB + 804 KBAcceptedScore: 4

Testcase #6548.987 ms407 MB + 8 KBAcceptedScore: 4

Testcase #7546.74 ms406 MB + 984 KBAcceptedScore: 4

Testcase #896.695 ms64 MB + 32 KBAcceptedScore: 4

Testcase #9106.856 ms60 MB + 428 KBAcceptedScore: 4

Testcase #10221.38 ms126 MB + 28 KBAcceptedScore: 4

Testcase #11263.25 ms121 MB + 228 KBAcceptedScore: 4

Testcase #12366.502 ms189 MB + 408 KBAcceptedScore: 4

Testcase #13442.613 ms184 MB + 372 KBAcceptedScore: 4

Testcase #14507.433 ms254 MB + 924 KBAcceptedScore: 4

Testcase #15632.799 ms249 MB + 388 KBAcceptedScore: 4

Testcase #16658.947 ms320 MB + 432 KBAcceptedScore: 4

Testcase #17827.258 ms314 MB + 604 KBAcceptedScore: 4

Testcase #18418.837 ms134 MB + 608 KBAcceptedScore: 4

Testcase #19529.88 ms195 MB + 228 KBAcceptedScore: 4

Testcase #20643.619 ms257 MB + 584 KBAcceptedScore: 4

Testcase #21736.708 ms320 MB + 540 KBAcceptedScore: 4

Testcase #22756.762 ms320 MB + 392 KBAcceptedScore: 4

Testcase #23754.644 ms320 MB + 336 KBAcceptedScore: 4

Testcase #24748.351 ms320 MB + 512 KBAcceptedScore: 4

Testcase #25745.055 ms320 MB + 548 KBAcceptedScore: 4


Judge Duck Online | 评测鸭在线
Server Time: 2024-12-05 10:38:57 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠