1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
| #include<iostream> #include<cstring> #include<algorithm> #include<cstdio> #include<vector> #include<queue> #include<stack> #include<bitset> #include<set> using namespace std; #define int long long typedef long long ll; #define MAXN 500006 #define MAXM 450 #define pb push_back #define pii pair<int,int> #define fi first #define se second #define mp make_pair #define inf 0x3f3f3f3f #define cmx( a , b ) a = max( a , b ) #define cmn( a , b ) a = min( a , b ) #define upd( a , b ) ( a = ( a + b ) % P ) #define P 998244353 void read( signed& x ) { scanf("%d",&x); } void read( ll& x ) { scanf("%lld",&x); } int n , m , s; struct node { int l , r , b; }; int ls[MAXN << 3] , rs[MAXN << 3] , T[MAXN << 3] , cn , rt[MAXN]; void mdfy( int &rt , int l , int r , int p , int c ) { if( !rt ) rt = ++ cn; T[rt] += c , T[rt] %= P; if( l == r ) return; int m = l + r >> 1; if( p <= m ) mdfy( ls[rt] , l , m , p , c ); else mdfy( rs[rt] , m + 1 , r , p , c ); } int query( int rt , int l , int r , int L , int R ) { if( !rt ) return 0; if( L <= l && R >= r ) return T[rt]; int m = l + r >> 1 , res = 0; if( L <= m ) res += query( ls[rt] , l , m , L , R ) , res %= P; if( R > m ) res += query( rs[rt] , m + 1 , r , L , R ) , res %= P;; return res; } bool cmp( node a , node b ) { return a.l == b.l ? a.r < b.r : a.l > b.l; } vector<node> V[MAXN] , S[MAXN]; int dp[MAXN]; signed main() { read( n ) , read( m ) , read( s ); for( int i = 1 , l , r , b ; i <= m ; ++ i ) read( l ) , read( r ) , read( b ) , V[b].pb( (node) { l , r , b } ); for( int i = 1 ; i <= s ; ++ i ) { sort( V[i].begin( ) , V[i].end( ) , cmp ); int minr = n + 1; for( int j = 0 ; j < V[i].size() ; ++ j ) if( V[i][j].r < minr ) S[V[i][j].r].pb( V[i][j] ) , minr = V[i][j].r; } dp[0] = 1; for( int i = 1 ; i <= n ; ++ i ) { dp[i] = dp[i - 1] * s % P; for( int j = 0 ; j < S[i].size() ; ++ j ) { int v = 0; v -= dp[S[i][j].l - 1] , v += P , v %= P; v -= query( rt[S[i][j].b] , 1 , n , S[i][j].l , S[i][j].r ) , v += P , v %= P; mdfy( rt[S[i][j].b] , 1 , n , i , v ); dp[i] += v , dp[i] %= P; } } cout << dp[n] << endl; }
|