#ifndef ONLINE_JUDGE #define _GLIBCXX_DEBUG #endif #include #include using namespace std; using namespace atcoder; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define bit(n,k) (((ll)n>>(ll)k)&1) /*nのk bit目*/ #define pb push_back #define pf push_front #define fi first #define se second #define eb emplace_back #define endl '\n' #define SZ(x) ((ll)(x).size()) #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define debug(v) cout<<#v<<":";for(auto x:v){cout< Point; // Point typedef long long ll; typedef vector vl; typedef vectorvvl; typedef vectorvvvl; typedef vectorvvvvl; typedef vectorvvvvvl; typedef pair P; typedef tuple T; template using minpq=priority_queue,greater>; // const ll MOD=1000000007LL; const ll MOD=998244353LL; const ll mod=MOD; string abc="abcdefghijklmnopqrstuvwxyz"; string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; vl dx={0,0,1,-1,1,1,-1,-1}; vl dy={1,-1,0,0,-1,1,-1,1}; template vector make_vec(size_t a) { return vector(a); } template auto make_vec(size_t a, Ts... ts) { return vector(ts...))>(a, make_vec(ts...)); } templatebool chmax(T &a,const T &b){if(abool chmin(T &a,const T &b){if(b 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); cout << fixed << setprecision(12); /*--------------------------------*/ int n,q;cin>>n>>q; vl a(n); rep(i,n)cin>>a[i]; sort(all(a)); vl b(n); vl l(q),r(q),p(q); rep(i,q)cin>>l[i]>>r[i]>>p[i]; vvl ans(q); //(値,個数) mapfirst; maplast; b[0]=1; first[1]=1; last[1]=a[0]; rep(i,n-1){ if(a[i+1]==a[i])b[i+1]=b[i]; else { b[i+1]=b[i]+1; first[b[i+1]]=last[b[i]]+1; last[b[i+1]]=a[i+1]; } } ll t=b[n-1]; //累積積 vector pro(n+1); pro[0]=1; for(int i=0;i(2,n+1); dp[n%2][0]=1; for(int i=n-1;i>=0;i--){ for(int j=n;j>=0;j--){ dp[i%2][j]=0; if(j)dp[i%2][j]+=dp[(i+1)%2][j-1]; dp[i%2][j]+=dp[(i+1)%2][j]*(a[i]-1); } if(i==0||a[i]!=a[i-1]){ //終端 //ここで更新 ll big,small; if(i==0){ big=a[i]; small=1; } else{ big=a[i]; small=a[i-1]+1; } rep(j,q){ if(max(l[j],small)<=min(r[j],big)){ ll cnt=min(r[j],big)-max(l[j],small)+1; mint value=pro[i]*dp[i%2][p[j]]; if(cnt%2)ans[j].pb(value.val()); } } } } for(ll i=0;i