結果

問題 No.1226 I hate Robot Arms
ユーザー hamamuhamamu
提出日時 2020-09-11 22:51:06
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 7,208 bytes
コンパイル時間 3,196 ms
コンパイル使用メモリ 225,332 KB
実行使用メモリ 126,468 KB
最終ジャッジ日時 2023-08-30 10:15:22
合計ジャッジ時間 43,421 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 4 ms
4,944 KB
testcase_02 AC 464 ms
17,912 KB
testcase_03 AC 611 ms
33,340 KB
testcase_04 AC 925 ms
117,500 KB
testcase_05 AC 849 ms
124,736 KB
testcase_06 AC 1,976 ms
122,512 KB
testcase_07 AC 430 ms
19,236 KB
testcase_08 AC 386 ms
118,680 KB
testcase_09 AC 1,104 ms
32,420 KB
testcase_10 AC 112 ms
11,352 KB
testcase_11 AC 1,047 ms
116,352 KB
testcase_12 AC 501 ms
60,868 KB
testcase_13 AC 536 ms
125,236 KB
testcase_14 AC 1,332 ms
33,440 KB
testcase_15 AC 312 ms
121,400 KB
testcase_16 AC 1,923 ms
125,152 KB
testcase_17 AC 458 ms
35,512 KB
testcase_18 AC 323 ms
36,520 KB
testcase_19 AC 1,060 ms
119,760 KB
testcase_20 AC 968 ms
117,140 KB
testcase_21 AC 1,265 ms
114,392 KB
testcase_22 AC 1,967 ms
126,204 KB
testcase_23 AC 1,998 ms
126,328 KB
testcase_24 TLE -
testcase_25 AC 1,974 ms
126,340 KB
testcase_26 TLE -
testcase_27 AC 1,892 ms
126,416 KB
testcase_28 AC 1,891 ms
126,248 KB
testcase_29 AC 1,903 ms
126,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
using     ll=long long;
using    vll=vector<   ll>;
using   vvll=vector<  vll>;
using  vvvll=vector< vvll>;
using vvvvll=vector<vvvll>;
constexpr ll INF = 1LL << 60;
struct Fast{ //cin,cout高速化のおまじない+桁数指定
	Fast(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(std::numeric_limits<double>::max_digits10); }
} fast;
#define REPS(i, S, E) for (ll i = (S); i <= (E); i++)
#define REP(i, N) REPS(i, 0, (N)-1)
#define DEPS(i, S, E) for (ll i = (E); i >= (S); i--)
#define DEP(i, N) DEPS(i, 0, (N)-1)
#define rep(i, S, E)  for (ll i = (S); i <= (E); i++)
#define dep(i, E, S)  for (ll i = (E); i >= (S); i--)
#define each(e, v) for (auto&& e : v)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; }return false; }
template<class T> inline T MaxE(vector<T>&v,ll S,ll E){ T m=v[S]; rep(i,S,E)chmax(m,v[i]); return m; }
template<class T> inline T MinE(vector<T>&v,ll S,ll E){ T m=v[S]; rep(i,S,E)chmin(m,v[i]); return m; }
template<class T> inline T MaxE(vector<T> &v) { return MaxE(v,0,(ll)v.size()-1); }
template<class T> inline T MinE(vector<T> &v) { return MinE(v,0,(ll)v.size()-1); }
template<class T> inline T Sum(vector<T> &v,ll S,ll E){ T s=T(); rep(i,S,E)s+=v[i]; return s; }
template<class T> inline T Sum(vector<T> &v) { return Sum(v,0,v.size()-1); }
template<class T> inline ll sz(T &v){ return (ll)v.size(); }
template<class T> inline T POW(T a, ll n){ T r=1; for (; n>0; n>>=1, a*=a){ if (n&1)r*=a; } return r; }
inline ll POW(int a, ll n){ return POW((ll)a, n); }
inline ll CEIL(ll a, ll b){ return (a+b-1)/b; }

using     dd=double;
using    vdd=vector<   dd>;
using   vvdd=vector<  vdd>;

template<class T> struct MatG{
	ll h=0, w=0; //h行w列
	vector<vector<T>> mat;
	MatG(){}
	MatG(ll h_, ll w_, T x) { init(h_, w_, x); }
	MatG(ll h_, ll w_) { init(h_, w_); }
	MatG(ll h_, ll w_, string c) { init(h_, w_, c); }
	void init(ll h_, ll w_, T x){ h=h_; w=w_; mat.assign(h, vector<T>(w,x)); }
	void init(ll h_, ll w_){ init(h_,w_,T()); }
	void init(ll h_, ll w_, string c){ init(h_, w_); if(c=="E")E(); }
	ll H() const { return h; }
	ll W() const { return w; }
	vector<T> &operator[](ll i) { return mat[i]; }
	const vector<T> &operator[](ll i) const { return mat[i]; }
	MatG<T> &operator+=(const MatG<T> &B) {REP(i,h)REP(j,w) mat[i][j]+=B[i][j];return *this;}
	MatG<T> operator+(const MatG<T> &B) const {return MatG<T>(*this) += B;}
	MatG<T> operator*(const MatG<T> &B) const {
		MatG<T> ret(h, B.W());
		REP(i, h) REP(j, B.W()) REP(k, w) ret[i][j] += mat[i][k] * B[k][j];
		return move(ret);
	}
	vector<T> operator*(const vector<T> &v) const {
		vector<T> ret(v.size());
		REP(i, this->h) REP(j, this->w) ret[i] += this->mat[i][j] * v[j];
		return move(ret);
	}
	MatG<T> Pow(ll N) const {
		MatG<T> ret(*this), a(*this);
		for (ll n=N-1; n>0; n>>=1, a=a*a){ if (n&1) ret=ret*a; }
		return move(ret);
	}
	MatG<T> t() const {
		MatG<T> ret(this->w, this->h);
		REP(i, this->w) REP(j, this->h) ret[i][j] = this->mat[j][i];
		return move(ret);
	}
	void E(){ rep(i, 0, min(h,w)-1) mat[i][i]=1; }
	//void dump() { ::dump(mat); }
	MatG(MatG<T> &&B){ *this=move(B); } //以下、ムーブ対応
	MatG(MatG<T> const &B){ *this=B; }
	MatG<T> &operator=(MatG<T> &&B){ h=B.h; w=B.w; mat.swap(B.mat); return *this; }
	MatG<T> &operator=(MatG<T> const &B){ h=B.h; w=B.w; mat=B.mat; return *this; }
};
using Mat = MatG<dd>;

template<class T> struct SegmentTree{
	using F = function<T(T, T)>;
	vector<T> dat; //第i要素 dat[i+n-1]
	ll n; //要素数以上の最小の 2のべき乗
	F f;
	T ti;
	SegmentTree(){}
	SegmentTree(vector<T> &v, F f, T ti){ Init(v, f, ti); }
	void Init(vector<T> &v, F f, T ti){
		this->f=f; this->ti=ti;
		for (n = 1; n < (ll)v.size(); n *= 2);
		dat.resize(2*n-1, ti);
		REP(i, (ll)v.size()) { dat[i+n-1] = v[i]; }//初期化
		DEP(i, n-1) { dat[i] = f(dat[2*i+1], dat[2*i+2]); }//構築
	}
	void Set(ll i, T x){ //第i要素にxをセット
		i += n-1;  dat[i] = x;
		while (i>0) { i=(i-1)/2; dat[i]=f(dat[2*i+1], dat[2*i+2]); }
	}
	T Range(ll a, ll b) { return range(a, b+1, 0, 0, n); }
	T operator [] (ll i) { return dat[i+n-1]; }
	void Dump(ll w=5){
		REP(i, n) for (ll k=i+n-1, m=1, p=1; k>=0; p=m, m*=k%2, k=(k==0)?-1:(k-1)/2){
			if (m) cerr << ((k<n-1)?" ┬ ":"") << setw(w) << dat[k];
			else   cerr << ((p&~m) ?" ┘ ":"");
			if (k==0) cerr << '\n';
		} cerr << '\n';
	}
	T range(ll a, ll b, ll k, ll l, ll r){ //注目ノードk=[l,r)
		if (r<=a || b<=l) return ti; //完全に外
		if (a<=l && r<=b) return dat[k];//完全に含まれる
		return f(range(a, b, k*2+1, l, (l+r)/2), range(a, b, k*2+2, (l+r)/2, r));
	}
	ll FindL(ll a, ll b, T x) { return findL(a, b+1, x, 0, 0, n); }
	ll findL(ll a, ll b, T x, ll k, ll l, ll r){ //[l,r)内最左 なければb
		if (r<=a || b<=l || f(dat[k], x)!=dat[k]) return b; //範囲外or満たさない
		if (k >= n-1) return k-(n-1); //葉なら見つかった→位置return
		ll        i = findL(a, b, x, 2*k+1, l, (l+r)/2); //左部分木探す
		if (i==b) i = findL(a, b, x, 2*k+2, (l+r)/2, r); //左になければ右
		return i;
	}
	ll FindR(ll a, ll b, T x) { return findR(a, b+1, x, 0, 0, n); }
	ll findR(ll a, ll b, T x, ll k, ll l, ll r){ //[l,r)内最右 なければa-1
		if (r<=a || b<=l || f(dat[k], x)!=dat[k]) return a-1; //範囲外or満たさない
		if (k >= n-1) return k-(n-1); //葉なら見つかった→位置return
		ll          i = findR(a, b, x, 2*k+2, (l+r)/2, r); //右部分木探す
		if (i==a-1) i = findR(a, b, x, 2*k+1, l, (l+r)/2); //右になければ左
		return i;
	}
};


void solve()
{
	ll n,q;  cin >> n >> q;

	vdd rads(n);
	vll ds(n,1);
	Mat mate(4,4,"E");
	Mat inimat(4,4,"E");
	inimat[0][2]=1.;
	inimat[1][3]=1.;

	vector<Mat> ini(n,inimat);

	SegmentTree<Mat> sgt(
		ini, //全初期値の入ったvector
		[](Mat x, Mat y){return y*x;}, //データ同士の合成関数
		mate //単位元
	);
	auto setmt=[&](Mat &mt, dd d, dd rad){
		mt[0][0]=1.;
		mt[0][2]=d*cos(rad);
		mt[0][3]=-d*sin(rad);

		mt[1][1]=1.;
		mt[1][2]=d*sin(rad);
		mt[1][3]=d*cos(rad);

		mt[2][2]= cos(rad);
		mt[2][3]=-sin(rad);

		mt[3][2]=sin(rad);
		mt[3][3]=cos(rad);
	};



	rep(qq,0,q-1){
		ll kind;  cin >> kind;
		if (kind==0){
			ll i,x;  cin >> i >> x;
			i--;
			dd rx=x*3.141592653589793238/180.;
			Mat mt(4,4);
			setmt(mt,(dd)ds[i],rx);
			sgt.Set(i,mt);
			rads[i]=rx;
		}
		else if (kind==1){
			ll i,x;  cin >> i >> x;
			i--;
			Mat mt(4,4);
			setmt(mt,(dd)x,rads[i]);
			sgt.Set(i,mt);
			ds[i]=x;
		}
		else{//kind==2
			ll i;  cin >> i;i--;
			Mat A = sgt.Range(0,i);
			vdd bg{0.,0.,1.,0.};
			vdd ans=A*bg;
			cout << ans[0] << " " << ans[1] << '\n';
		}
	}
}


int main(){
#if 1
	solve();
#else
	ll t;  cin >> t;
	rep(i, 0, t-1){
		solve();
	}
#endif
	return 0;
}
0