結果

問題 No.1226 I hate Robot Arms
ユーザー milanis48663220milanis48663220
提出日時 2020-11-23 21:23:42
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 6,523 bytes
コンパイル時間 2,329 ms
コンパイル使用メモリ 132,424 KB
実行使用メモリ 78,980 KB
最終ジャッジ日時 2023-10-01 00:08:25
合計ジャッジ時間 20,091 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 3 ms
4,472 KB
testcase_02 AC 563 ms
12,000 KB
testcase_03 AC 762 ms
21,856 KB
testcase_04 AC 1,011 ms
72,132 KB
testcase_05 AC 918 ms
78,688 KB
testcase_06 TLE -
testcase_07 AC 524 ms
13,224 KB
testcase_08 AC 314 ms
73,192 KB
testcase_09 AC 1,319 ms
21,168 KB
testcase_10 AC 134 ms
8,628 KB
testcase_11 AC 1,079 ms
70,816 KB
testcase_12 AC 547 ms
38,008 KB
testcase_13 AC 522 ms
78,948 KB
testcase_14 AC 1,615 ms
22,024 KB
testcase_15 AC 247 ms
75,312 KB
testcase_16 TLE -
testcase_17 AC 556 ms
23,992 KB
testcase_18 AC 383 ms
24,636 KB
testcase_19 AC 1,181 ms
74,312 KB
testcase_20 AC 1,098 ms
71,672 KB
testcase_21 AC 1,469 ms
69,304 KB
testcase_22 TLE -
testcase_23 TLE -
testcase_24 TLE -
testcase_25 TLE -
testcase_26 TLE -
testcase_27 TLE -
testcase_28 TLE -
testcase_29 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cassert>
#include <cmath>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template <typename T, typename S>
struct LazySegmentTree {
    int n;
    T unit;
    S unit_lazy;
    vector<T> node;
    vector<S> lazy;
    vector<bool> lazyFlag;

    T (*calc)(T, T);
    S (*propagateLazy)(S, S);
    T (*merge)(S, T);

    LazySegmentTree(vector<T> v, T UNIT, S UNIT_LAZY, T (*_calc)(T, T), S (*_propagateLazy)(S, S), T (*_merge)(S, T)) {
        int sz = (int)v.size();
        unit = UNIT;
        unit_lazy = UNIT_LAZY;
        calc = _calc;
        propagateLazy = _propagateLazy;
        merge = _merge;
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1, unit);
        lazy.resize(2*n-1, UNIT_LAZY);
        lazyFlag.resize(2*n-1, false);

        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = calc(node[i*2+1], node[i*2+2]);
    }

    void lazyEvaluate(int k, int l, int r) {
        if(lazyFlag[k]) {
            node[k] = merge(lazy[k], node[k]);
            if(r - l > 1) {
                lazy[k*2+1] = propagateLazy(lazy[k*2+1], lazy[k]);
                lazy[k*2+2] = propagateLazy(lazy[k*2+2], lazy[k]);
                lazyFlag[k*2+1] = lazyFlag[k*2+2] = true;
            }
            lazyFlag[k] = false;
            lazy[k] = unit_lazy;
        }
    }

    //[a, b)
    //区間[a, b]への更新に対してはupdate(a, b+1, x)と呼ぶ
    void update(int a, int b, S x, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        lazyEvaluate(k, l, r);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b) {
            lazy[k] = propagateLazy(lazy[k], x);
            lazyFlag[k] = true;
            lazyEvaluate(k, l, r);
        }
        else {
            update(a, b, x, 2*k+1, l, (l+r)/2);
            update(a, b, x, 2*k+2, (l+r)/2, r);
            node[k] = calc(node[2*k+1], node[2*k+2]);
        }
    }

    //[a, b)
    //区間[a, b]へのクエリに対してはquery(a, b+1)と呼ぶ
    T query(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        lazyEvaluate(k, l, r);
        if(b <= l || r <= a) return unit;
        if(a <= l && r <= b) return node[k];
        T vl = query(a, b, 2*k+1, l, (l+r)/2);
        T vr = query(a, b, 2*k+2, (l+r)/2, r);
        return calc(vl, vr);
    }
};

template <typename T>
struct matrix{
    int n, m;
    vector<vector<T>> dat;
    matrix(int n_ = 0, int m_ = 0){
        n = n_; m = m_;
        for(int i = 0; i < n; i++){
            dat.push_back(vector<T>(m));
        }
    }
    vector<T>& operator[](int x) {
        return dat[x];
	}
};

template <typename T>
void prod(matrix<T> a, matrix<T> b, matrix<T> &ans){
    assert(a.m == b.n);
    for(int i = 0; i < a.n; i++){
        for(int j = 0; j < a.m; j++){
            ans.dat[i][j] = 0;
            for(int k = 0; k < b.m; k++){
                ans.dat[i][j] += (a.dat[i][k]*b.dat[k][j]);
            }
        }
    }
}

template <typename T>
matrix<T> prod(matrix<T> a, matrix<T> b){
    assert(a.m == b.n);
    matrix<T> ans(a.n, b.m);
    for(int i = 0; i < a.n; i++){
        for(int j = 0; j < a.m; j++){
            ans.dat[i][j] = 0;
            for(int k = 0; k < b.n; k++){
                ans.dat[i][j] += (a.dat[i][k]*b.dat[k][j]);
            }
        }
    }
    return ans;
}

template <typename T>
matrix<T> add(matrix<T> a, matrix<T> b){
    assert(a.n == b.n);
    assert(a.m == b.m);
    matrix<T> ans(a.n, a.m);
    for(int i = 0; i < a.n; i++){
        for(int j = 0; j < a.m; j++){
            ans[i][j] = a[i][j]+b[i][j];
        }
    }
    return ans;
}

template <typename T>
void copy_mat(matrix<T> a, matrix<T> &b){
    assert(a.n == b.n);
    assert(a.m == b.m);
    for(int i = 0; i < a.n; i++){
        for(int j = 0; j < a.m; j++){
            b.dat[i][j] = a.dat[i][j];
        }
    }
}

template <typename T>
void pow_mat(matrix<T> a, ll n, matrix<T> &ans){
    matrix<T> buf(a.n, a.n);
    matrix<T> tmp(a.n, a.n);
    copy_mat(a, tmp);

    for(int i = 0; i < a.n; i++) {
        for(int j = 0; j < a.n; j++){
            ans.dat[i][j] = 0;
        }
        ans.dat[i][i] = 1;
    }
    
    for(int i = 0; i <= 30; i++){
        ll m = (ll)1 << i;
        if(m&n){
            prod(tmp, ans, buf);
            copy_mat(buf, ans);
        }
        prod(tmp, tmp, buf);
        copy_mat(buf, tmp);
    }
}

template <typename T>
void print_mat(matrix<T> a){
    for(int i = 0; i < a.n; i++){
        for(int j = 0; j < a.m; j++){
            cout << a.dat[i][j] << ' ';
        }
        cout << endl;
    }
}

struct lazy{
    double theta, d;
};

matrix<double> merge(lazy l, matrix<double> node){
    assert(node.n == 2);
    assert(node.m == 1);
    matrix<double> ans(2, 1);
    ans[0][0] = l.d*(cos(l.theta)*node[0][0]-sin(l.theta)*node[1][0]);
    ans[1][0] = l.d*(sin(l.theta)*node[0][0]+cos(l.theta)*node[1][0]);
    return ans;
}

lazy propagate(lazy x, lazy y){
    return (lazy){x.theta+y.theta, x.d*y.d};
}

double d[100000], theta[100000];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n, q; cin >> n >> q;
    matrix<double> unit_vec(2, 1), unit_mat(2, 2);
    unit_mat[0][0] = 1.0; unit_mat[1][1] = 1.0;
    vector<matrix<double>> v(n);
    for(int i = 0; i < n; i++) {
        matrix<double> m(2, 1);
        m[0][0] = 1.0;
        v[i] = m;
        d[i] = 1.0;
    }
    LazySegmentTree<matrix<double>,lazy> sgt(v, unit_vec, (lazy){0.0, 1.0}, add, propagate, merge);
    for(int _ = 0; _ < q; _++){
        int t, i; cin >> t >> i; i--;
        double x;
        if(t == 0){
            cin >> x;
            x = x*M_PI/180.0;
            sgt.update(i, n, (lazy){x-theta[i], 1.0});
            theta[i] = x;
        }else if(t == 1){
            cin >> x;
            sgt.update(i, i+1, (lazy){0.0, x/d[i]});
            d[i] = x;
        }else{
            auto r = sgt.query(0, i+1);
            cout << r[0][0] << ' ' << r[1][0] << endl;
        }
    }
}
0