#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; template struct LazySegmentTree { private: vector node; vector lazy; int siz,log; void map_and_comp(F f,int u) { node[u] = mapping(f,node[u]); if(u < siz) lazy[u] = composition(f,lazy[u]); } void propagate(int u) { assert(0 <= u && u < siz); map_and_comp(lazy[u],2*u); map_and_comp(lazy[u],2*u+1); lazy[u] = id(); } void recalculate(int u) {node[u] = op(node[2*u],node[2*u+1]);} public: LazySegmentTree(int n = 0) : LazySegmentTree(vector(n,e())) {} LazySegmentTree(const vector &V) { siz = 1; log = 0; while(siz < (int)V.size()) siz <<= 1,log++; node.assign(2*siz,e()); lazy.assign(siz,id()); for(int i = 0;i < (int)V.size();i++) node[i+siz] = V[i]; for(int i = siz-1;i >= 1;i--) recalculate(i); } void fill(T x,int l = 0,int r = -1) {if(r < 0){r = siz;} for(int i = l;i < r;i++) replace(i,x);} void clear() {fill(e());} void replace(int pos,T x) {func_update(pos,x,[](T u,T v){return u = v;});} void add(int pos,T x) {func_update(pos,x,[](T u,T v){return u + v;});} void func_update(int pos,T x,T (*func)(T,T)) { assert(0 <= pos && pos < siz); pos += siz; for(int i = log;i >= 1;i--) propagate(pos >> i); node[pos] = func(node[pos],x); for(int i = 1;i <= log;i++) recalculate(pos >> i); } T operator[](int pos) { assert(0 <= pos && pos < siz); pos += siz; for(int i = log;i >= 1;i--) propagate(pos >> i); return node[pos]; } void apply(int pos,F f) { assert(0 <= pos && pos < siz); pos += siz; for(int i = log;i >= 1;i--) propagate(pos >> i); node[pos] = mapping(f,node[pos]); for(int i = 1;i <= log;i++) recalculate(pos >> i); } void apply(int l,int r,F f) { assert(0 <= l && l <= r && r <= siz); if(l == r) return; l += siz; r += siz; int l0 = l/(l & -l); int r0 = r/(r & -r); for(int i = log;i >= 1;i--) propagate(l0 >> i); for(int i = log;i >= 1;i--) propagate((r0-1) >> i); while(l < r) { if(l & 1) map_and_comp(f,l++); if(r & 1) map_and_comp(f,--r); l >>= 1; r >>= 1; } for(int i = 1;i <= log;i++) recalculate(l0 >> i); for(int i = 1;i <= log;i++) recalculate((r0-1) >> i); } T prod() {return node[1];} T prod(int l,int r) { assert(0 <= l && l <= r && r <= siz); l += siz; r += siz; int l0 = l/(l & -l); int r0 = r/(r & -r); for(int i = log;i >= 1;i--) propagate(l0 >> i); for(int i = log;i >= 1;i--) propagate((r0-1) >> i); T Lval = e(),Rval = e(); while(l < r) { if(l & 1) Lval = op(Lval,node[l++]); if(r & 1) Rval = op(node[--r],Rval); l >>= 1; r >>= 1; } return op(Lval,Rval); } }; template struct mat { private: vector> m; int h,w; public: constexpr mat(int _h,int _w,T x = 0) noexcept {m.assign(_h,vector(_w,x));h = _h,w = _w;} constexpr vector operator[](const int i) const {assert(0 <= i && i < h); return m[i];} constexpr vector &operator[](const int i) noexcept {assert(0 <= i && i < h); return m[i];} constexpr mat operator+(mat &other) noexcept { mat tmp = *this; return tmp += other; } constexpr mat operator-(mat &other) noexcept { mat tmp = *this; return tmp -= other; } constexpr mat operator*(mat &other) noexcept { mat tmp = *this; return tmp *= other; } constexpr mat &operator+=(mat &other) noexcept { assert(h == other.h && w == other.w); for(int i = 0;i < h;i++)for(int j = 0;j < w;j++) m[i][j] += other[i][j]; return *this; } constexpr mat &operator-=(mat &other) noexcept { assert(h == other.h && w == other.w); for(int i = 0;i < h;i++)for(int j = 0;j < w;j++) m[i][j] -= other[i][j]; return *this; } constexpr mat &operator*=(mat &other) noexcept { assert(w == other.h); mat tmp(h,other.w); for(int i = 0;i < h;i++)for(int j = 0;j < other.w;j++)for(int k = 0;k < w;k++) tmp[i][j] += m[i][k]*other[k][j]; for(int i = 0;i < h;i++) { m[i].resize(other.w); for(int j = 0;j < other.w;j++) m[i][j] = tmp[i][j]; } return *this; } constexpr mat power(long n) noexcept { assert(h == w); assert(n >= 0); mat res(h,w); for(int i = 0;i < h;i++) res[i][i] = 1; mat p = *this; long ex = n; while(ex) { if(ex & 1) res *= p; p *= p; ex >>= 1; } return res; } constexpr bool operator==(mat &other) noexcept { assert(h == other.h && w == other.w); bool res = true; for(int i = 0;i < h;i++)for(int j = 0;j < w;j++) if(m[i][j] != other[i][j]) res = false; return res; } constexpr bool operator!=(mat &other) noexcept { assert(h == other.h && w == other.w); bool res = false; for(int i = 0;i < h;i++)for(int j = 0;j < w;j++) if(m[i][j] != other[i][j]) res = true; return res; } template friend ostream &operator<<(ostream &os,const mat &x); }; template ostream &operator<<(ostream &os,const mat &x) { for(int i = 0;i < x.h;i++)for(int j = 0;j < x.w;j++) { os << x[i][j] << (j+1 == x.w && i+1 < x.h ? "\n":" "); return os; } } void solve() { int N,Px,Py; cin >> N >> Px >> Py; vector> M(N,mat(3,3)); for(int i = 0;i < N;i++) { int t; cin >> t; if(t == 1) { int d; cin >> d; for(int j = 0;j < 3;j++) M[i][j][j] = 1; M[i][0][2] = d; } else if(t == 2) { int d; cin >> d; for(int j = 0;j < 3;j++) M[i][j][j] = 1; M[i][1][2] = d; } else { M[i][0][1] = 1; M[i][1][0] = -1; M[i][2][2] = 1; } } mat op(3,3); for(int i = 0;i < 3;i++) op[i][i] = 1; mat S(3,1); S[0][0] = Px,S[1][0] = Py,S[2][0] = 1; vectorX(N),Y(N); for(int i = N;i--;) { op = op * M[i]; mat cur = op * S; X[i] = cur[0][0],Y[i] = cur[1][0]; } for(int i = 0;i < N;i++) cout << X[i] << " " << Y[i] << "\n"; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int tt = 1; /* cin >> tt; */ while(tt--) solve(); }