結果

問題 No.1932 動く点 P / Moving Point P
ユーザー 沙耶花沙耶花
提出日時 2022-05-06 22:16:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,690 ms / 6,000 ms
コード長 2,549 bytes
コンパイル時間 5,549 ms
コンパイル使用メモリ 280,432 KB
実行使用メモリ 77,360 KB
最終ジャッジ日時 2023-09-20 03:12:46
合計ジャッジ時間 38,596 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 851 ms
72,660 KB
testcase_02 AC 536 ms
71,400 KB
testcase_03 AC 1,183 ms
8,348 KB
testcase_04 AC 1,496 ms
21,624 KB
testcase_05 AC 1,342 ms
22,240 KB
testcase_06 AC 263 ms
38,484 KB
testcase_07 AC 2,690 ms
77,204 KB
testcase_08 AC 2,682 ms
77,360 KB
testcase_09 AC 1,759 ms
77,284 KB
testcase_10 AC 1,777 ms
77,324 KB
testcase_11 AC 1,784 ms
77,204 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000000

template <class S,
          S (*op0)(S, S),
          S (*e0)(),
		  S (*op1)(S, S),
          S (*e1)()
          >
struct matrix{
	vector<vector<S>> v;
	int _h,_w;
	
	matrix(){
	}
	
	matrix(vector<vector<S>> X){
		v = X;
		_h = X.size();
		_w = 0;
		if(X.size()>0)_w = X[0].size();
	}
	
	matrix(int h,int w){
		v.resize(h,vector<S>(w,e0()));
		_h = h;
		_w = w;
	}
	
	void add_element(int from,int to,S x){
		v[to][from] = op0(v[to][from],x);
	}
	
	matrix e(){
		assert(_h==_w);
		matrix<S,op0,e0,op1,e1> ret(_h,_w);
		for(int i=0;i<_h;i++){
			for(int j=0;j<_w;j++){
				if(i==j)ret.v[i][j] = e1();
				else ret.v[i][j] = e0();
			}
		}
		return ret;
	}
	
	matrix &operator*=(const matrix &another){
		matrix<S,op0,e0,op1,e1> ret(_h,another._w);
		for(int i=0;i<_h;i++){
			for(int j=0;j<another._w;j++){
				ret.v[i][j] = e0();
				for(int k=0;k<_w;k++){
					ret.v[i][j] = op0(ret.v[i][j],op1(v[i][k],another.v[k][j]));
				}
			}
		}

		v = ret.v;
		return (*this);
	}
	
	matrix operator*(const matrix &another)const{
		return (matrix(*this)*=another);
	}
	
	matrix pow(long long cnt){
		matrix<S,op0,e0,op1,e1> ret = e();
		auto temp = *this;
		while(cnt!=0LL){
			if((cnt&1)==1){
				ret *= temp;
			}
			temp *= temp;
			cnt>>=1;
		}
		return ret;
	}
};

double op0(double a,double b){
	return a+b;
}

double e0(){
	return 0.0;
}

double op1(double a,double b){
	return a*b;
}

double e1(){
	return 1.0;
}

using M = matrix<double,op0,e0,op1,e1>;

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

M e(){
	M ret(3,3);
	return ret.e();
}

int main(){
	
	int N,Q;
	cin>>N;
	
	vector<M> temp(N);
	
	rep(i,N){
		auto t = e();
		double p,q,r;
		cin>>p>>q>>r;
		
		t.add_element(2,0,-p);
		t.add_element(2,1,-q);
		
		{
			M tt(3,3);
			tt.add_element(2,2,1);
			r /= 360.0;
			r *= acos(-1.0) * 2.0;
			tt.add_element(0,0,cos(r));
			tt.add_element(1,0,-sin(r));
			tt.add_element(0,1,sin(r));
			tt.add_element(1,1,cos(r));
			t = tt* t;
		}
		
		{
			auto tt = e();
			tt.add_element(2,0,p);
			tt.add_element(2,1,q);
			t = tt*t;
		}
		temp[i] = t;
	}
	
	segtree<M,op,e> seg(temp);
	
	cin>>Q;
	
	rep(_,Q){
		
		int s,t;
		cin>>s>>t;
		double x,y;
		cin>>x>>y;
		M tt(3,1);
		tt.v[0][0] = x;
		tt.v[1][0]=y;
		tt.v[2][0]=1.0;
		tt = seg.prod(s-1,t) * tt;
		cout<<fixed<<setprecision(10)<<tt.v[0][0]<<' '<<tt.v[1][0]<<endl;
	}
		
	
    return 0;
}
0