結果

問題 No.675 ドットちゃんたち
ユーザー ゆにぽけゆにぽけ
提出日時 2024-01-03 16:29:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 141 ms / 2,000 ms
コード長 7,259 bytes
コンパイル時間 1,851 ms
コンパイル使用メモリ 140,960 KB
実行使用メモリ 25,216 KB
最終ジャッジ日時 2024-01-03 16:29:12
合計ジャッジ時間 4,681 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 1 ms
6,548 KB
testcase_02 AC 1 ms
6,548 KB
testcase_03 AC 1 ms
6,548 KB
testcase_04 AC 2 ms
6,548 KB
testcase_05 AC 128 ms
25,216 KB
testcase_06 AC 141 ms
25,216 KB
testcase_07 AC 126 ms
23,040 KB
testcase_08 AC 134 ms
25,216 KB
testcase_09 AC 139 ms
25,216 KB
testcase_10 AC 140 ms
25,216 KB
testcase_11 AC 138 ms
25,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <array>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cmath>
#include <ctime>
#include <iomanip>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <random>
#include <utility>
#include <functional>
using namespace std;
template<class T,T (*op)(T,T),T e(),class F,T (*mapping)(F,T),F (*composition)(F,F),F id()> struct LazySegmentTree
{
    private:
    vector<T> node;
    vector<F> 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<T>(n,e())) {}
    LazySegmentTree(const vector<T> &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<class T> struct mat
{
    private:
    vector<vector<T>> m;
    int h,w;

    public:
    constexpr mat(int _h,int _w,T x = 0) noexcept {m.assign(_h,vector<T>(_w,x));h = _h,w = _w;}

    constexpr vector<T> operator[](const int i) const {assert(0 <= i && i < h); return m[i];}

    constexpr vector<T> &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<class S> friend ostream &operator<<(ostream &os,const mat<S> &x);
};

template<class S> ostream &operator<<(ostream &os,const mat<S> &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<mat<long long>> M(N,mat<long long>(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<long long> op(3,3);
	for(int i = 0;i < 3;i++) op[i][i] = 1;
	mat<long long> S(3,1);
	S[0][0] = Px,S[1][0] = Py,S[2][0] = 1;
	vector<long long>X(N),Y(N);
	for(int i = N;i--;)
	{
		op = op * M[i];
		mat<long long> 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();
}

0