#include #include using namespace std; using namespace atcoder; using ll = long long; using mint=modint998244353; using ld = long double; const ll infl = 1LL << 60; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const vector dx = {1, 0, -1, 0}; const vector dy = {0, 1, 0, -1}; template using vc = vector; template using vvc = vc>; template using vvvc = vc>; using vi = vc; using vvi = vvc; using vl = vc; using vvl = vvc; using vvvl = vvc; using vvvvl = vvc; using vs = vc; using vvs = vvc; using P = pair; #define nrep(i,n) for (ll i = 0; i < (n); ++i) #define nfor(i,s,n) for(ll i=s;i using pq = priority_queue>;//★大きい順に取り出す コスト,頂点 bfs系で使う 小さい順じゃないですABC305E template using pq_g = priority_queue, greater>;//小さい順に取り出す ダイクストラ法で使う #define cout(n) cout<> K >> N; segtree seg(N); nrep(i, N) { vvl mat(2, vl(2)); nrep(r,2) nrep(c,2) { cin >> mat[r][c]; mat[r][c] = (mat[r][c] + (ll)1e12 / K * K) % K; } seg.set(i, Matrix(mat)); } ll Q; cin >> Q; while (Q--) { ll i, l, r; cin >> i >> l >> r; --i; --l; --r; vvl y(2, vl(2)); nrep(r,2) nrep(c,2) { cin >> y[r][c]; y[r][c] = (y[r][c] + (ll)1e12 / K * K) % K; } seg.set(i, Matrix(y)); Matrix res = seg.prod(l, r + 1); nrep(r,2) cout << res.v[r][0] % K << ' ' << res.v[r][1] % K << '\n'; } }