結果

問題 No.1226 I hate Robot Arms
ユーザー KKT89KKT89
提出日時 2022-04-30 14:30:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 265 ms / 2,000 ms
コード長 3,796 bytes
コンパイル時間 1,521 ms
コンパイル使用メモリ 135,668 KB
実行使用メモリ 12,688 KB
最終ジャッジ日時 2023-09-12 07:09:36
合計ジャッジ時間 10,714 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 66 ms
4,380 KB
testcase_03 AC 79 ms
5,116 KB
testcase_04 AC 110 ms
10,052 KB
testcase_05 AC 110 ms
12,024 KB
testcase_06 AC 219 ms
11,624 KB
testcase_07 AC 62 ms
4,380 KB
testcase_08 AC 51 ms
10,352 KB
testcase_09 AC 138 ms
5,236 KB
testcase_10 AC 18 ms
4,380 KB
testcase_11 AC 117 ms
9,728 KB
testcase_12 AC 62 ms
6,976 KB
testcase_13 AC 75 ms
12,092 KB
testcase_14 AC 168 ms
5,368 KB
testcase_15 AC 47 ms
11,092 KB
testcase_16 AC 228 ms
12,216 KB
testcase_17 AC 61 ms
5,948 KB
testcase_18 AC 44 ms
6,440 KB
testcase_19 AC 123 ms
10,708 KB
testcase_20 AC 112 ms
10,092 KB
testcase_21 AC 141 ms
9,188 KB
testcase_22 AC 239 ms
12,352 KB
testcase_23 AC 240 ms
12,284 KB
testcase_24 AC 236 ms
12,688 KB
testcase_25 AC 235 ms
12,304 KB
testcase_26 AC 238 ms
12,488 KB
testcase_27 AC 265 ms
12,556 KB
testcase_28 AC 262 ms
12,600 KB
testcase_29 AC 262 ms
12,668 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <sstream>
#include <utility>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <array>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}
inline double time() {
    return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}

struct point{
    long double x,y;
    point() {}
    point(long double x,long double y): x(x), y(y) {}
    point& operator-=(const point &p){
        x -= p.x; y -= p.y;
        return *this;
    }
    point& operator+=(const point &p){
        x += p.x; y += p.y;
        return *this;
    }
    point& operator*=(long double d){
        x *= d; y *= d;
        return *this;
    }
    point& operator/=(long double d){
        x /= d; y /= d;
        return *this;
    }
    const point operator+ (const point& p) const;
    const point operator- (const point& p) const;
    const point operator* (long double d) const;
    const point operator/ (long double d) const;
};
const point point::operator+ (const point& p) const{
    point res(*this); return res += p;
}
const point point::operator- (const point& p) const{
    point res(*this); return res -= p;
}
const point point::operator* (long double d) const{
    point res(*this); return res *= d;
}
const point point::operator/ (long double d) const{
    point res(*this); return res /= d;
}

long double abs(point P){
    return sqrt(P.x*P.x+P.y*P.y);
}

point rotate(point p, double theta){
    return point(p.x*cos(theta)-p.y*sin(theta), p.x*sin(theta)+p.y*cos(theta));
}

template <class S, S (*op)(S, S), S (*e)()>
struct segtree {
    int n;
    vector<S> tree;
    segtree() : segtree(0) {}
    segtree(int n) : n(n), tree(vector<S>(n<<1, e())) {}
    void update(int k) { tree[k] = op(tree[k<<1|0], tree[k<<1|1]); }
    S operator[](int i) {return tree[i+n]; }
    void set(int i, S x) {
        i += n;
        tree[i] = x;
        while(i >>= 1) {
            update(i);
        }
    }
    // [l,r)
    S query(int l, int r) {
        S sml = e(), smr = e();
        for(l += n, r += n; l < r; l >>= 1, r >>= 1){
            if(l & 1) sml = op(sml, tree[l++]);
            if(r & 1) smr = op(tree[--r], smr);
        }
        return op(sml,smr);
    }
};

// ベクトルと回転角度を持つ
using P = pair<point,long double>;
P op(P a,P b){
    auto p = a.first;
    auto pp = b.first;
    p += rotate(pp, a.second);
    return {p, a.second+b.second};
}
P e() {return {{0,0},0};};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,q; cin >> n >> q;
    segtree<P,op,e> seg(n);
    for(int i=0;i<n;i++){
        seg.set(i, {{1,0},0});
    }
    while(q--){
        int type; cin >> type;
        int i; cin >> i; i--;
        auto P = seg[i];
        auto &p = P.first;
        if(type == 1){
            int w; cin >> w;
            p =  p / abs(p) * w;
            seg.set(i, P);
        }
        else if(type == 0){
            int w; cin >> w;
            long double theta = acos(-1.0L) * (w) / 180.0;
            p = rotate(p, -P.second+theta);
            P.second = theta;
            seg.set(i, P);
        }
        else{
            auto res = seg.query(0, i+1);
            double x = res.first.x, y = res.first.y;
            printf("%.9f %.9f\n",x, y);
        }
    }
}

0