#include<iostream> #include<algorithm> #include<cstring> #include<cstdio> usingnamespace std; #define MAXN 1000006 #define int long long #define P 998244353 int n , m; int J[MAXN << 1]; intpower( int a , int x ){ int ans = 1 , cur = a % P; while( x ) { if( x & 1 ) ans *= cur , ans %= P; cur *= cur , cur %= P , x >>= 1; } return ans; } intC( int a , int b ){ return J[a] * power( J[b] * J[a - b] % P , P - 2 ) % P; } signedmain(){ cin >> n >> m; J[0] = 1; for( int i = 1 ; i < MAXN * 2 ; ++ i ) J[i] = J[i - 1] * i % P; cout << ( C( 2 * n , n + m ) - C( 2 * n , n + m + 1 ) + P ) % P << endl; }
#include<iostream> #include<cstring> #include<cstdio> #include<algorithm> usingnamespace std; #define MAXN 6006 int n , P , res = 0; int A[MAXN] , pos[MAXN]; int up[MAXN] , dw[MAXN];
intmain(){ cin >> n >> P; for( int i = 1 ; i <= n ; ++ i ) scanf("%d",&A[i]) , pos[A[i]] = i , up[i] = 1 , dw[i] = 0; for( int i = n ; i >= 1 ; -- i ) for( int j = 1 ; j < i ; ++ j ) if( pos[j] > pos[i] ) up[i] += dw[j] , up[i] %= P; else dw[j] += up[i] , dw[j] %= P; for( int i = 1 ; i <= n ; ++ i ) res += up[i] , res %= P , up[i] = 1 , dw[i] = 0; for( int i = 1 ; i <= n ; ++ i ) for( int j = n ; j > i ; -- j ) if( pos[j] > pos[i] ) up[i] += dw[j] , up[i] %= P; else dw[j] += up[i] , dw[j] %= P; for( int i = 1 ; i <= n ; ++ i ) res += up[i] , res %= P; cout << ( ( res - n ) % P + P ) % P << endl; }