結果

問題 No.1226 I hate Robot Arms
ユーザー outlineoutline
提出日時 2021-01-07 22:53:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 5,476 bytes
コンパイル時間 1,850 ms
コンパイル使用メモリ 150,220 KB
実行使用メモリ 16,152 KB
最終ジャッジ日時 2024-04-26 15:33:12
合計ジャッジ時間 11,500 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template<typename Monoid, typename OperatorMonoid = Monoid>
struct LazySegmentTree{
    using F = function<Monoid(Monoid, Monoid)>;
    using G = function<Monoid(Monoid, OperatorMonoid)>;
    using H = function<OperatorMonoid(OperatorMonoid, OperatorMonoid)>;

    int sz;
    vector<Monoid> data;
    vector<OperatorMonoid> lazy;
    const F f;
    const G g;
    const H h;
    const Monoid M1;            // モノイドの単位元
    const OperatorMonoid OM0;   // 作用素モノイドの単位元

    LazySegmentTree(int n, const F f, const G g, const H h, const Monoid &M1, const OperatorMonoid OM0)
        : f(f), g(g), h(h), M1(M1), OM0(OM0)
    {
        sz = 1;
        while(sz < n)   sz <<= 1;
        data.assign(sz << 1, M1);
        lazy.assign(sz << 1, OM0);
    }

    void set(int k, const Monoid &x){
        data[k + sz] = x;
    }

    void build(){
        for(int k = sz - 1; k > 0; --k){
            data[k] = f(data[k << 1], data[k << 1 | 1]);
        }
    }

    void propagate(int k){
        if(lazy[k] != OM0){
            if(k < sz){
                lazy[k << 1] = h(lazy[k << 1], lazy[k]);
                lazy[k << 1 | 1] = h(lazy[k << 1 | 1], lazy[k]);
            }
            data[k] = g(data[k], lazy[k]);
            lazy[k] = OM0;
        }
    }

    Monoid update(int a, int b, const OperatorMonoid &x, int k = 1, int l = 0, int r = -1){
        if(r == -1)     r = sz;
        propagate(k);
        if(r <= a || b <= l)    return data[k];
        else if(a <= l && r <= b){
            lazy[k] = h(lazy[k], x);
            propagate(k);
            return data[k];
        }
        else{
            return data[k] = f(update(a, b, x, k << 1, l, (l + r) >> 1),
                                update(a, b, x, k << 1 | 1, (l + r) >> 1, r));
        }
    }

    Monoid query(int a, int b, int k = 1, int l = 0, int r = -1){
        if(r == -1)     r = sz;
        propagate(k);
        if(r <= a || b <= l)    return M1;
        else if(a <= l && r <= b)   return data[k];
        else{
            return f(query(a, b, k << 1, l, (l + r) >> 1),
                        query(a, b, k << 1 | 1, (l + r) >> 1, r));
        }
    }

    Monoid operator[](const int &k){
        return query(k, k + 1);
    }
};

const double pi = acos(-1);

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N, Q;
    cin >> N >> Q;

    // x, y : 座標
    // d : leaf node のベクトルの大きさ
    // theta : phi を基準としたときの偏角
    struct node {
        double x, y;
        int d, theta, phi;
        node(double x = 0.0, double y = 0.0, int d = 0, int theta = 0, int phi = 0)
            : x(x), y(y), d(d), theta(theta), phi(phi) {}
    };
    auto op = [](node a, node b) {
        return node(a.x + b.x, a.y + b.y, 0, a.theta, a.phi);
    };
    // (angle, (leaf node)(d, angle), flag)
    using opnode = tuple<int, int, int, bool>;
    auto mapping = [](node a, opnode b) {
        auto [s, t, u, f] = b;
        double nx, ny;
        int nd, ntheta, nphi;
        if(a.d == 0){   // not leaf node
            double ang = s * pi / 180.0;
            nx = a.x * cos(ang) - a.y * sin(ang);
            ny = a.x * sin(ang) + a.y * cos(ang);
            nd = 0;
            ntheta = a.theta;
            nphi = a.phi + s;
        }
        else{   // leaf node
            double ang = (a.phi + s + a.theta + u) * pi / 180.0;
            nx = cos(ang); ny = sin(ang);
            nd = t != 0 ? t : a.d;
            nx *= nd; ny *= nd;
            ntheta = a.theta + u;
            nphi = a.phi + s;
        }
        return node(nx, ny, nd, ntheta, nphi);
    };
    auto composition = [](opnode a, opnode b) {
        auto [s, t, u, f] = a;
        auto [x, y, z, g] = b;
        return opnode(s + x, t + y, u + z, f | g);
    };
    LazySegmentTree<node, opnode> seg(N, op, mapping, composition, node(), opnode(0, 0, 0, false));
    for(int i = 0; i < N; ++i){
        seg.set(i, node(1, 0, 1, 0, 0));
    }
    seg.build();

    cout << fixed << setprecision(10);
    for(int q = 0; q < Q; ++q){
        int t, i, x;
        cin >> t >> i;
        --i;
        if(t != 2)  cin >> x;
        if(t == 0){
            seg.update(i, i + 1, opnode(0, 0, x, true));
            seg.update(i + 1, N, opnode(x, 0, 0, true));
        }
        else if(t == 1){
            seg.update(i, i + 1, opnode(0, x, 0, true));
        }
        else{
            auto res = seg.query(0, i + 1);
            cout << res.x << ' ' << res.y << '\n';
        }
    }

    return 0;
}
0