結果

問題 No.1226 I hate Robot Arms
ユーザー outlineoutline
提出日時 2021-01-08 01:52:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 520 ms / 2,000 ms
コード長 4,339 bytes
コンパイル時間 1,637 ms
コンパイル使用メモリ 145,272 KB
実行使用メモリ 22,252 KB
最終ジャッジ日時 2024-04-26 18:12:30
合計ジャッジ時間 15,636 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 136 ms
6,016 KB
testcase_03 AC 173 ms
8,320 KB
testcase_04 AC 204 ms
21,632 KB
testcase_05 AC 187 ms
21,888 KB
testcase_06 AC 482 ms
21,884 KB
testcase_07 AC 129 ms
6,272 KB
testcase_08 AC 51 ms
21,632 KB
testcase_09 AC 302 ms
8,448 KB
testcase_10 AC 35 ms
5,376 KB
testcase_11 AC 216 ms
21,504 KB
testcase_12 AC 124 ms
12,672 KB
testcase_13 AC 98 ms
22,144 KB
testcase_14 AC 393 ms
8,192 KB
testcase_15 AC 31 ms
21,888 KB
testcase_16 AC 454 ms
21,888 KB
testcase_17 AC 115 ms
8,576 KB
testcase_18 AC 79 ms
8,448 KB
testcase_19 AC 220 ms
21,856 KB
testcase_20 AC 211 ms
21,740 KB
testcase_21 AC 296 ms
21,516 KB
testcase_22 AC 463 ms
22,048 KB
testcase_23 AC 468 ms
21,976 KB
testcase_24 AC 472 ms
22,252 KB
testcase_25 AC 489 ms
22,144 KB
testcase_26 AC 469 ms
22,108 KB
testcase_27 AC 512 ms
22,144 KB
testcase_28 AC 520 ms
22,016 KB
testcase_29 AC 497 ms
22,056 KB
権限があれば一括ダウンロードができます

ソースコード

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);
    }
};

using ld = long double;
using Point = complex<ld>;
const ld pi = acos(-1);

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

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

    vector<int> ang(N);
    vector<ld> len(N, 1.0);
    auto op = [](Point a, Point b) { return a + b; };
    auto mapping = [](Point a, Point b) { return a * b; };
    auto composition = [](Point a, Point b) { return a * b; };
    LazySegmentTree<Point, Point> seg(N, op, mapping, composition, Point(0, 0), Point(1, 0));
    for(int i = 0; i < N; ++i)  seg.set(i, Point(1, 0));
    seg.build();

    cout << fixed << setprecision(10);
    for(int q = 0; q < Q; ++q){
        int t, i, x;
        cin >> t >> i;
        if(t != 2)  cin >> x;
        --i;
        if(t == 0){
            seg.update(i, N, polar((ld)1.0, (x - ang[i]) * pi / 180.0));
            ang[i] = x;
        }
        else if(t == 1){
            ld ratio = x / len[i];
            seg.update(i, i + 1, Point(ratio, 0));
            len[i] = x;
        }
        else{
            auto res = seg.query(0, i + 1);
            cout << res.real() << ' ' << res.imag() << '\n';
        }
    }

    return 0;
}
0