#line 1 "..\\Main.cpp" #include #include #include #include #include #line 1 "D:\\Programming\\VSCode\\competitive-cpp\\nachia\\array\\dual-segment-tree.hpp" #line 3 "D:\\Programming\\VSCode\\competitive-cpp\\nachia\\array\\dual-segment-tree.hpp" namespace nachia{ template< class F, F composition(F f, F x) > struct DualSegtree { struct Node { F f; bool propagated; }; int N; int logN; std::vector A; void mapf(Node& a, F f) { a.propagated = false; a.f = composition(f, a.f); } void spread(int i) { if(A[i].propagated || !(i < N)) return; mapf(A[i*2], A[i].f); mapf(A[i*2+1], A[i].f); A[i] = A[0]; } DualSegtree(int n, F id) { N=1; logN=0; while(N& a) : DualSegtree(a.size()) { for(int i=0; i> d); A[p] = A[0]; } F get(int p){ p += N; for(int d=logN; d; d--) spread(p >> d); return A[p].f; } void apply(int l, int r, F f){ if(!(l < r)) return; if(l == 0 && r == N){ mapf(A[1], f); return; } l += N; r += N; for(int d=logN; d; d--){ if((l >> d) << d != l) spread(l >> d); if((r >> d) << d != r) spread(r >> d); } while(l < r){ if(l&1){ mapf(A[l++], f); } l /= 2; if(r&1){ mapf(A[--r], f); } r /= 2; } } void apply(int p, F f){ p += N; for(int d=logN; d; d--) spread(p >> d); mapf(A[p], f); } }; } // namespace nachia; #line 8 "..\\Main.cpp" using namespace std; using i32 = int; using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; #define rep(i,n) for(int i=0; i<(int)(n); i++) const i64 INF = 1001001001001001001; //using Modint = atcoder::static_modint<998244353>; using Modint = atcoder::modint; struct S{ Modint z=1, xz=1, y=1; }; struct F{ Modint YY=1, XY=0, ZY=0; Modint XX=1, ZX=0; Modint ZZ=1; }; F composition(F f, F x){ return { x.YY*f.YY, x.XX*f.XY + x.XY*f.YY, x.ZZ*f.ZY + x.ZX*f.XY + x.ZY*f.YY, x.XX*f.XX, x.ZZ*f.ZX + x.ZX*f.XX, x.ZZ*f.ZZ }; } int main(){ int N; cin >> N; int B; cin >> B; Modint::set_mod(B); int Q; cin >> Q; auto rq = nachia::DualSegtree(N, F()); rep(q,Q){ int l,m,r; cin >> l >> m >> r; l--; m--; rq.apply(l, r, {3,2,2,3,3,3}); auto g = rq.get(m); auto x = g.XX + g.ZX; auto y = g.XY + g.YY + g.ZY; auto z = g.ZZ; cout << x.val() << ' ' << y.val() << ' ' << z.val() << '\n'; } return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ ios::sync_with_stdio(false); cin.tie(nullptr); } } ios_do_not_sync_instance;