QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#409441#7512. Almost Prefix ConcatenationSortingWA 0ms36472kbC++205.3kb2024-05-12 04:26:052024-05-12 04:26:05

Judging History

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

  • [2024-05-12 04:26:05]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:36472kb
  • [2024-05-12 04:26:05]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair < int , int > pii ;
typedef vector < int > vi ;
#define fi first
#define se second
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()

const int MAXN = 2e6 + 7 ;
const int MOD = 998244353 ;
const int LOG = 22 ;

int n , m ;
string a , b ;

class Tree {
public :
    ll sm[ 4 * MAXN ] , ways[ 4 * MAXN ] , ans[ 4 * MAXN ] ;
    void init ( int w , int l , int r ) {
        sm[ w ] = ways[ w ] = ans[ w ] = 0 ;
        if ( l == r ) { return ; }
        int mid = ( l + r ) / 2 ;
        init ( 2 * w , l , mid ) ;
        init ( 2 * w + 1 , mid + 1 , r ) ;
    }
    void update ( int w , int l , int r , int pos , ll add_ans , ll add_sm , ll add_ways  ) {
        if ( l == r ) {
            ans[ w ] = ( ans[ w ] + add_ans ) % MOD ;
            sm[ w ] = ( sm[ w ] + add_sm ) % MOD ;
            ways[ w ] = ( ways[ w ] + add_ways ) % MOD ;
            return ;
        }
        int mid = ( l + r ) / 2 ;
        if ( pos <= mid ) { update ( 2 * w , l , mid , pos , add_ans , add_sm , add_ways ) ; }
        else { update ( 2 * w + 1 , mid + 1 , r , pos , add_ans , add_sm , add_ways ) ; }
        sm[ w ] = ( sm[ 2 * w ] + sm[ 2 * w + 1 ] ) % MOD ;
        ways[ w ] = ( ways[ 2 * w ] + ways[ 2 * w + 1 ] ) % MOD ;
        ans[ w ] = ( ans[ 2 * w ] + ans[ 2 * w + 1 ] ) % MOD ;
    }
    ll get_sm ( int w , int l , int r , int st , int en ) {
        if ( l > r || st > en ) { return 0 ; }
        if ( r < st || en < l ) { return 0 ; }
        if ( st <= l && r <= en ) { return sm[ w ] ; }
        int mid = ( l + r ) / 2 ;
        return ( get_sm ( 2 * w , l , mid , st , en ) + get_sm ( 2 * w + 1 , mid + 1 , r , st , en ) ) % MOD ;
    }
    ll get_ways ( int w , int l , int r , int st , int en ) {
        if ( l > r || st > en ) { return 0 ; }
        if ( r < st || en < l ) { return 0 ; }
        if ( st <= l && r <= en ) { return ways[ w ] ; }
        int mid = ( l + r ) / 2 ;
        return ( get_ways ( 2 * w , l , mid , st , en ) + get_ways ( 2 * w + 1 , mid + 1 , r , st , en ) ) % MOD ;
    }
    ll get_ans ( int w , int l , int r , int st , int en ) {
        if ( l > r || st > en ) { return 0 ; }
        if ( r < st || en < l ) { return 0 ; }
        if ( st <= l && r <= en ) { return ans[ w ] ; }
        int mid = ( l + r ) / 2 ;
        return ( get_ans ( 2 * w , l , mid , st , en ) + get_ans ( 2 * w + 1 , mid + 1 , r , st , en ) ) % MOD ;        
    }
};
Tree w ;


struct SuffixArray {
	vi sa, lcp;
	SuffixArray(string& s, int lim=256) { // or basic_string<int>
		int n = sz(s) + 1, k = 0, a, b;
		vi x(all(s)+1), y(n), ws(max(n, lim)), rank(n);
		sa = lcp = y, iota(all(sa), 0);
		for (int j = 0, p = 0; p < n; j = max(1, j * 2), lim = p) {
			p = j, iota(all(y), n - j);
			rep(i,0,n) if (sa[i] >= j) y[p++] = sa[i] - j;
			fill(all(ws), 0);
			rep(i,0,n) ws[x[i]]++;
			rep(i,1,lim) ws[i] += ws[i - 1];
			for (int i = n; i--;) sa[--ws[x[y[i]]]] = y[i];
			swap(x, y), p = 1, x[sa[0]] = 0;
			rep(i,1,n) a = sa[i - 1], b = sa[i], x[b] =
				(y[a] == y[b] && y[a + j] == y[b + j]) ? p - 1 : p++;
		}
		rep(i,1,n) rank[sa[i]] = i;
		for (int i = 0, j; i < n - 1; lcp[rank[i++]] = k)
			for (k && k--, j = sa[rank[i] - 1];
					s[i + k] == s[j + k]; k++);
	}
};

int pos[ MAXN ] ;
int rmq[ LOG ][ MAXN ] ;
int mxpw[ MAXN ] ;

int get_eq ( int x , int y ) {
    if ( x > n || y > m ) { return 0 ; }
    x = pos[ m + x + 1 ] , y = pos[ y ] ;
    if ( x > y ) { swap ( x , y ) ; }
    ++ x ;
    if ( x > y ) { return 0 ; }
    int len = y - x + 1 ;
    int id = mxpw[ len ] ;
    return min ( rmq[ id ][ x ] , rmq[ id ][ y - ( 1 << id ) + 1 ] ) ;
}

int get_mx ( int l ) {
    int hh1 = get_eq ( l , 1 ) ;
    if ( hh1 == m || l + hh1 - 1 == n ) { return hh1 ; }
    int hh2 = get_eq ( l + hh1 + 1 , hh1 + 2 ) ;
    return hh1 + 1 + hh2 ;
}

ll dp[ MAXN ] , sm[ MAXN ] , ways[ MAXN ] ;

void solve ( ) {
    cin >> a >> b ;
    n = a.size ( ) , m = b.size ( ) ;
    string s = b + '#' + a ;
    int sz = s.size ( ) ;
    SuffixArray aux ( s ) ;
    for ( int i = 1 ; i <= sz ; ++ i ) {
        rmq[ 0 ][ i ] = aux.lcp[ i ] ;
        pos[ aux.sa[ i ] + 1 ] = i ;
    }
    for ( int i = 1 ; i <= sz ; ++ i ) {
        mxpw[ i ] = mxpw[ i - 1 ] ;
        if ( 2 * ( 1 << mxpw[ i ] ) < i ) { ++ mxpw[ i ] ; }
    }
    for ( int lvl = 1 ; lvl < LOG ; ++ lvl ) {
        for ( int i = 1 ; i + ( 1 << lvl ) - 1 <= sz ; ++ i ) {
            rmq[ lvl ][ i ] = min ( rmq[ lvl - 1 ][ i ] , rmq[ lvl - 1 ][ i + ( 1 << ( lvl - 1 ) ) ] ) ;
        }
    }
    w.init ( 1 , 1 , n + 1 ) ;
    w.update ( 1 , 1 , n + 1 , n + 1 , 0 , 0 , 1 ) ;
    for ( int i = n ; i >= 1 ; -- i ) {
        int r = i + get_mx ( i ) - 1 ;
        ll x = w.get_ans ( 1 , 1 , n + 1 , i + 1 , r + 1 ) ;
        ll y = w.get_sm ( 1 , 1 , n + 1 , i + 1 , r + 1 ) ;
        ll z = w.get_ways ( 1 , 1 , n + 1 , i + 1 , r + 1 ) ;

        ways[ i ] = z ;
        sm[ i ] = y + z ;
        dp[ i ] = x + 2 * y + z ;
        w.update ( 1 , 1 , n + 1 , i , dp[ i ] , sm[ i ] , ways[ i ] ) ;
    }
    cout << dp[ 1 ] << "\n" ;
}

int main ( ) {
    ios_base :: sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
    int t = 1 ; // cin >> t ;
    while ( t -- ) { solve ( ) ; }
    return 0 ;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

ababaab
aba

output:

473

result:

ok 1 number(s): "473"

Test #2:

score: 0
Accepted
time: 0ms
memory: 22160kb

input:

ac
ccpc

output:

5

result:

ok 1 number(s): "5"

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 36472kb

input:

qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq...

output:

2071527403

result:

wrong answer 1st numbers differ - expected: '75038697', found: '2071527403'