結果

問題 No.1932 動く点 P / Moving Point P
ユーザー milanis48663220milanis48663220
提出日時 2022-05-06 23:18:06
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 764 ms / 6,000 ms
コード長 3,878 bytes
コンパイル時間 2,342 ms
コンパイル使用メモリ 125,652 KB
実行使用メモリ 30,920 KB
最終ジャッジ日時 2023-09-20 05:57:24
合計ジャッジ時間 23,190 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 237 ms
28,828 KB
testcase_02 AC 146 ms
28,316 KB
testcase_03 AC 363 ms
4,840 KB
testcase_04 AC 431 ms
9,860 KB
testcase_05 AC 491 ms
10,136 KB
testcase_06 AC 73 ms
16,032 KB
testcase_07 AC 764 ms
30,808 KB
testcase_08 AC 764 ms
30,920 KB
testcase_09 AC 654 ms
30,816 KB
testcase_10 AC 663 ms
30,872 KB
testcase_11 AC 657 ms
30,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>
#include <atcoder/segtree>

#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>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

double deg2rad(double deg){
    return deg*M_PI/180.0;
}

template<typename T, int N, int M>
class Matrix {
    public:
    array<array<T, M>, N> dat;
    Matrix(T val) {
        for(int i = 0; i < N; i++){
            for(int j = 0; j < M; j++){
                dat[i][j] = val;
            }
        }
    }

    Matrix(array<array<T, M>, N> dat): dat(dat){  }
    array<T, M>& operator[](int x) {
        return dat[x];
	}
};

template<typename T, int N, int M, int K>
Matrix<T, N, K> operator*(Matrix<T, N, M> a, Matrix<T, M, K> b){
    Matrix<T, N, K> c(T(0));
    for(int i = 0; i < N; i++){
        for(int j = 0; j < K; j++){
            for(int k = 0; k < M; k++){
                c.dat[i][j] += a.dat[i][k]*b.dat[k][j];
            }
        }
    }
    return c;
}

template <typename T, int N, int M>
void print_mat(Matrix<T, N, M> a){
    for(int i = 0; i < N; i++){
        for(int j = 0; j < M; j++){
            cout << a.dat[i][j] << ' ';
        }
        cout << endl;
    }
}

template <typename T, int N, int M>
ostream& operator<<(ostream& os, const Matrix<T, N, M>& m){
    print_mat<T, N, M>(m);
    return os;
}

using M = Matrix<double, 3, 3>;
using V = Matrix<double, 3, 1>;

M e_(){
    M ans(0.0);
    for(int i = 0; i < 3; i++) ans[i][i] = 1.0;
    return ans;
}

M I = e_();

M e(){
    return I;
}

M rot(double t){
    M ans(0.0);
    ans[2][2] = 1;
    ans[0][0] = cos(t);
    ans[0][1] = -sin(t);
    ans[1][0] = sin(t);
    ans[1][1] = cos(t);
    return ans;
}

M move_mat(double p, double q){
    M ans(0.0);
    ans[0][0] = 1;
    ans[1][1] = 1;
    ans[2][2] = 1;
    ans[0][2] = p;
    ans[1][2] = q;
    return ans;
}

M op(M a, M b){
    return a*b;
}

M calc(double t, double p, double q){
    return move_mat(p, q)*rot(t)*move_mat(-p, -q);
}

using Seg = atcoder::segtree<M, op, e>;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n; cin >> n;
    vector<double> p(n), q(n), r(n);
    Seg seg(n);
    for(int i = 0; i < n; i++){
        cin >> p[i] >> q[i] >> r[i];
        r[i] = deg2rad(r[i]);
        // cout << calc(r[i], p[i], q[i]) << endl;
        seg.set(n-i-1, calc(r[i], p[i], q[i]));
    }
    int Q; cin >> Q;
    while(Q--){
        int s, t; cin >> s >> t; s--; t--;
        double x, y; cin >> x >> y;
        s = n-1-s;
        t = n-1-t;
        swap(s, t);
        M m = seg.prod(s, t+1);
        // cout << s << ' ' << t << endl;
        V v(0.0);
        v[0][0] = x;
        v[1][0] = y;
        v[2][0] = 1;
        V u = m*v;
        // cout << m << endl;
        // cout << u << endl;
        cout << u[0][0] << ' ' << u[1][0] << endl;
    }
}
0