結果

問題 No.675 ドットちゃんたち
ユーザー FF256grhyFF256grhy
提出日時 2018-04-13 23:41:07
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 113 ms / 2,000 ms
コード長 4,574 bytes
コンパイル時間 1,528 ms
コンパイル使用メモリ 170,668 KB
実行使用メモリ 12,876 KB
最終ジャッジ日時 2023-09-09 04:52:03
合計ジャッジ時間 3,525 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 88 ms
12,572 KB
testcase_06 AC 113 ms
12,560 KB
testcase_07 AC 97 ms
12,876 KB
testcase_08 AC 91 ms
12,564 KB
testcase_09 AC 99 ms
12,844 KB
testcase_10 AC 107 ms
12,576 KB
testcase_11 AC 97 ms
12,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

template<typename T> class SegTree {
private:
	T * a = NULL;
	int N = -1, S;
	function<T(T, T)> F;
	T I;
	bool is_available = false;

public:
	SegTree() { }
	SegTree(int n, function<T(T, T)> func, T id) { init(n, func, id); }
	
	// [0, n) が使用可能になる、func が演算、id は単位元
	void init(int size, function<T(T, T)> func, T id) {
		assert(size > 0);
		N = size;
		F = func;
		I = id;
		S = 1;
		while(S < size) { S *= 2; }
		delete[] a;
		a = new T[S * 2];
		inc(i, S * 2) { a[i] = I; }
		is_available = true;
	}
	
	// [p] の値を返す
	T operator[](int p) {
		assert(inID(p, 0, N));
		p += S;
		return a[p];
	}
	
	// [p] への参照を返す(calc() を呼ぶまで fold は使用不能になる)
	T & ref(int p) {
		is_available = false;
		assert(inID(p, 0, N));
		p += S;
		return a[p];
	}
	
	// テーブル全体を再計算
	void calc() {
		decID(i, 1, S) { a[i] = F(a[i * 2], a[i * 2 + 1]); }
		is_available = true;
	}
	
	// [p] に op を適用しテーブルを更新
	void apply(int p, function<void(T &)> op) {
		assert(inID(p, 0, N));
		p += S;
		op(a[p]);
		while(p != 1) {
			p /= 2;
			a[p] = F(a[p * 2], a[p * 2 + 1]);
		}
	}
	
	// [l, r) に f を適用した結果を返す
	T fold_ID(int l, int r, bool loop = false) {
		assert(is_available);
		assert(inII(l, 0, N));
		assert(inII(r, 0, N));
		if(loop && l >= r) { return F(fold_ID(l, N), fold_ID(0, r)); }
		assert(l <= r);
		l += S;
		r += S;
		T v = I, w = I;
		while(l < r) {
			if(l + 1 == r) { v = F(v, a[l]); break; }
			
			if(l % 2 == 1) { v = F(v, a[l]); }
			if(r % 2 == 1) { w = F(a[r - 1], w); }
			
			l = (l + 1) / 2;
			r = r / 2;
		}
		return F(v, w);
	}
	
	// [l, r] に f を適用した結果を返す
	T fold_II(int l, int r, bool loop = false) { return fold_ID(l, r + 1, loop); }
};

#define OP(op) [&](auto a, auto b) { return op; }
#define AP(op) [&](auto & a) { op; }

// ---- ----

template<int N, typename T> class Matrix {
public:
	T a[N][N];
	
	Matrix() {
		inc(i, N) {
		inc(j, N) {
			a[i][j] = 0;
		}
		}
	}
	
	Matrix(T l[N][N]) {
		inc(i, N) {
		inc(j, N) {
			a[i][j] = l[i][j];
		}
		}
	}
	
	Matrix operator*(const Matrix & m) const {
		Matrix x;
		inc(i, N) {
		inc(j, N) {
		inc(k, N) {
			x.a[i][j] += a[i][k] * m.a[k][j];
		}
		}
		}
		return x;
	}
};

template<int N, typename T> Matrix<N, T> unit() {
	Matrix<N, T> m;
	inc(i, N) { m.a[i][i] = 1; }
	return m;
}

// ----

int n, px, py;

int main() {
	cin >> n >> px >> py;
	
	SegTree<Matrix<3, int>> st(n, OP(b * a), unit<3, int>());
	
	inc(i, n) {
		int c;
		cin >> c;
		if(c == 3) {
			int r[3][3] = { { 0, +1, 0 }, { -1, 0, 0 }, { 0, 0, 1 } };
			st.ref(i) = Matrix<3, int>(r);
		} else {
			int d;
			cin >> d;
			int s[3][3] = { { 1, 0, (c == 1 ? d : 0) }, { 0, 1, (c == 2 ? d : 0) }, { 0, 0, 1 } };
			st.ref(i) = Matrix<3, int>(s);
		}
	}
	st.calc();
	
	inc(i, n) {
		int v[3][3] = { { px, 0, 0 }, { py, 0, 0 }, { 1, 0, 0 } };
		auto ans = st.fold_ID(i, n) * Matrix<3, int>(v);
		
		cout << ans.a[0][0] << " " << ans.a[1][0] << "\n";
	}
	
	return 0;
}
0