#include #pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; #define lli long long int #define uli unsigned long long int #define INF 9999999999 #define rep(i,m,n) for(lli i = m;i < n;i++) #define rrep(i,m,n) for(lli i=m-1;i>=n;i--) #define pb(n) push_back(n) #define UE(N) N.erase(unique(N.begin(),N.end()),N.end()); #define Sort(n) sort(n.begin(), n.end()) #define Rev(n) reverse(n.begin(),n.end()) #define Out(S) cout << S << endl #define NeOut(S) cout << S #define HpOut(S) cout << setprecision(50) << S << endl #define Vec(K,L,N,S) vector K(N,S) #define DV(K,L,N,M,S) vector> K(N,vector(M,S)) #define TV(K,L,N,M,R,S) vector>> K(N,vector>(M,vector(R,S))) #define pint pair #define paf(L,R) pair #define mod 998244353 #define MAX 10000000 #define ALL(a) a.begin(),a.end() #define chmax(a, b) a = (((a)<(b)) ? (b) : (a)) #define chmin(a, b) a = (((a)>(b)) ? (b) : (a)) int main(){ ios::sync_with_stdio(false); cin.tie(0); lli B,C,D,E,H,W,M,K,L,R,N,num=0,sum=0,flag=0;string S,T; cin >> N >> K; queueque; Vec(A,lli,N,0);//A'[i]=A[i]-1; Vec(RuiP,lli,N+1,1);//前からA_iの累積積 DV(RuiF,lli,N+1,0,0);//後ろから多項式の累積積 rep(i,0,N)cin >> A[i]; Sort(A); rep(i,0,N)RuiP[i+1]=RuiP[i]*A[i]%mod; RuiF[N].pb(1); rrep(i,N,0){ H=RuiF[i+1].size(); RuiF[i].resize(H+1); rep(j,0,H)RuiF[i][j]=RuiF[i+1][j]*(A[i]-1)%mod; rep(j,0,H)RuiF[i][j+1]=(RuiF[i][j+1]+RuiF[i+1][j])%mod; } rep(i,0,N+1)RuiF[i].resize(N+1); while(K--){ int l,r,p; cin >> l >> r >> p; sum=0; rep(i,l-1,r){ int ng=-1,ok=N+1; while(ok-ng>1){ int mid=(ok+ng)/2; if(A[mid]>i)ok=mid; else ng=mid; } sum^=(RuiP[ok]*RuiF[ok][p]%mod); } que.push(sum%mod); } /*rep(i,0,N+1)cout << RuiP[i] << " "; Out(""); rep(i,0,N+1){ for(auto v:RuiF[i])cout << v << " "; Out(""); }*/ while(!que.empty()){ Out(que.front()); que.pop(); } }