#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define pii pair<int,int>
#define x first
#define y second
#define vi vector<int>
#define vpi vector<pii>
#define all(x) (x).begin(),(x).end()
#define WT int TT=read();while(TT--)
using namespace std;
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
if(f)x=-x;return x;
}
inline void ckmax(int &a,int b){a=(a>b?a:b);}
inline void ckmin(int &a,int b){a=(a<b?a:b);}
const int Mod=998244353;
const int M=5e5+10;
int n,k,m,l[M],r[M],x[M],c[M],dp[M],ans=1;
vi e[M];
signed main()
{
n=read(),k=read(),m=read();
for (int i=1;i<=n;i++)e[i].clear();
for (int i=1;i<=m;i++)l[i]=read(),r[i]=read(),x[i]=read(),e[r[i]].pb(i);
for (int w=0;w<k;w++)
{
for (int i=1;i<=n;i++)c[i]=0;
for (int i=1;i<=m;i++)
if (x[i]>>w&1)c[l[i]]++,c[r[i]+1]--;
for (int i=1;i<=n;i++)c[i]+=c[i-1],dp[i]=0;
int pos=-1,S=1;dp[0]=1;
for (int i=1;i<=n;i++)
{
if (c[i]==0)
dp[i]=S,S=S*2%Mod;
for (auto id:e[i])
{
if (x[id]>>w&1)continue;
while(pos+1<l[id])pos++,S=(S-dp[pos]+Mod)%Mod,dp[pos]=0;
}
}
// cerr<<S<<'\n';
ans=ans*S%Mod;
}
cout<<ans<<'\n';
return 0;
}
27. Remove Element | 39. Combination Sum |
378. Kth Smallest Element in a Sorted Matrix | 162. Find Peak Element |
1529A - Eshag Loves Big Arrays | 19. Remove Nth Node From End of List |
925. Long Pressed Name | 1051. Height Checker |
695. Max Area of Island | 402. Remove K Digits |
97. Interleaving String | 543. Diameter of Binary Tree |
124. Binary Tree Maximum Path Sum | 1465. Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts |
501A - Contest | 160A- Twins |
752. Open the Lock | 1535A - Fair Playoff |
1538F - Interesting Function | 1920. Build Array from Permutation |
494. Target Sum | 797. All Paths From Source to Target |
1547B - Alphabetical Strings | 1550A - Find The Array |
118B - Present from Lena | 27A - Next Test |
785. Is Graph Bipartite | 90. Subsets II |
1560A - Dislike of Threes | 36. Valid Sudoku |