#include #include #include #include using namespace std; using ll = long long; using ull = unsigned long long; const ull M = 57384961; ull powm(ull a, ull i) { if(i==0) return 1; ull r=powm(a*a%M,i/2); if(i&1) r=r*a%M; return r; } ull invm(ull a){ return powm(a,M-2); } ull primitiveRoot(){ vector D; ull m = M-1; for(ull p=2; p*p<=m; p++) if(m%p==0){ D.push_back(p); while(m%p==0) m /= p; } if(m != 1) D.push_back(m); for(ull g=2; g<=M-1; g++){ bool ok = true; for(ull d : D) if(powm(g,(M-1)/d) == 1) ok = false; if(ok) return g; } exit(1); } void NTT(vector& A, ull g){ int N=A.size(); for(int i=0,j=0; j>1; k>(i^=k); k>>=1); } for(int i=1; i=M) A[k]-=M; A[k+i]=(l+M-r); if(A[k+i]>=M) A[k+i]-=M; } qj=qj*q%M; } } } const int maxT = 3000; const int NTTZ = 1<<13; const ull NTTg = primitiveRoot(); const ull NTTinvZ = invm(NTTZ); const ull NTTinvg = invm(NTTg); vector convolute(vector l, vector r){ NTT(l,NTTg); NTT(r,NTTg); vector ans(NTTZ,0); for(int i=0; i Idx; vector> VecList; vector AnsArr; int main(){ cin>>N>>Q; for(int q=0; q>K; int A,B,S,T; cin>>A>>B>>S>>T; if(Idx.count(K) == 0){ Idx[K] = VecList.size(); VecList.push_back(vector(NTTZ,0)); for(int i=0; i<=3000; i++) VecList.back()[i] = 1; } int idx = Idx[K]; for(int x=A; x<=B; x++) VecList[idx][x] = 0; AnsArr = vector(NTTZ,0); AnsArr[0] = 1; for(auto& vec : VecList) AnsArr = convolute(AnsArr, vec); ull leftN = N - VecList.size(); vector ansCoeff(NTTZ+1); ansCoeff[0] = 1; for(int i=1; i<=NTTZ; i++) ansCoeff[i] = ansCoeff[i-1] * ((leftN+i-1) % M) % M * invm(i) % M; reverse(ansCoeff.begin(),ansCoeff.end()); ansCoeff.push_back(0); reverse(ansCoeff.begin(),ansCoeff.end()); for(int i=0; i<=NTTZ; i++) ansCoeff[i+1] = (ansCoeff[i] + ansCoeff[i+1]) % M; ull ans = 0; for(int s=0; s