結果

問題 No.1226 I hate Robot Arms
ユーザー kotatsugamekotatsugame
提出日時 2020-09-11 21:43:49
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 372 ms / 2,000 ms
コード長 2,269 bytes
コンパイル時間 1,057 ms
コンパイル使用メモリ 94,264 KB
実行使用メモリ 13,308 KB
最終ジャッジ日時 2023-08-30 09:47:48
合計ジャッジ時間 15,073 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 106 ms
4,660 KB
testcase_03 AC 117 ms
5,824 KB
testcase_04 AC 128 ms
12,040 KB
testcase_05 AC 114 ms
12,872 KB
testcase_06 AC 296 ms
12,656 KB
testcase_07 AC 94 ms
4,688 KB
testcase_08 AC 34 ms
12,136 KB
testcase_09 AC 226 ms
5,772 KB
testcase_10 AC 26 ms
4,380 KB
testcase_11 AC 145 ms
12,116 KB
testcase_12 AC 79 ms
7,800 KB
testcase_13 AC 59 ms
12,884 KB
testcase_14 AC 265 ms
6,036 KB
testcase_15 AC 23 ms
12,972 KB
testcase_16 AC 298 ms
12,800 KB
testcase_17 AC 85 ms
6,172 KB
testcase_18 AC 55 ms
6,132 KB
testcase_19 AC 150 ms
12,340 KB
testcase_20 AC 134 ms
12,120 KB
testcase_21 AC 186 ms
11,860 KB
testcase_22 AC 306 ms
13,284 KB
testcase_23 AC 309 ms
13,308 KB
testcase_24 AC 306 ms
13,192 KB
testcase_25 AC 306 ms
13,088 KB
testcase_26 AC 308 ms
13,092 KB
testcase_27 AC 372 ms
13,252 KB
testcase_28 AC 366 ms
13,144 KB
testcase_29 AC 363 ms
13,180 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:52:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   52 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
#include<vector>
#include<functional>
#include<limits>
template<typename T>
struct segtree{
	using F=function<T(T,T)>;
	const F calcfn,updatefn;
	int n;
	T defvalue;
	vector<T>dat;
	segtree(int n_=0,T defvalue_=numeric_limits<T>::max(),
		const F calcfn_=[](T a,T b){return a<b?a:b;},
		const F updatefn_=[](T a,T b){return b;}
	):defvalue(defvalue_),calcfn(calcfn_),updatefn(updatefn_)
	{
		n=1;
		while(n<n_)n<<=1;
		dat.assign(2*n-1,defvalue);
	}
	void copy(const vector<T>&v)
	{
		for(int i=0;i<v.size();i++)dat[i+n-1]=v[i];
		for(int i=n-2;i>=0;i--)dat[i]=calcfn(dat[i*2+1],dat[i*2+2]);
	}
	void update(int i,T a)
	{
		i+=n-1;
		dat[i]=updatefn(dat[i],a);
		while(i>0)
		{
			i=(i-1)/2;
			dat[i]=calcfn(dat[2*i+1],dat[2*i+2]);
		}
	}
	T query(int a,int b)//[a,b)
	{
		int L=(a<0?0:a>n?n:a)+n-1;
		int R=(b<0?0:b>n?n:b)+n-1;
		T lret=defvalue,rret=defvalue;
		for(;L<R;L>>=1,R>>=1)
		{
			if(!(L&1))lret=calcfn(lret,dat[L]);
			if(!(R&1))rret=calcfn(dat[--R],rret);
		}
		return calcfn(lret,rret);
	}
};
main()
{
	int N,Q;
	cin>>N>>Q;
	segtree<pair<pair<double,double>,double> >P(
		N,
		make_pair(make_pair(0,0),0),
		[](pair<pair<double,double>,double>a,pair<pair<double,double>,double>b)
		{
			return make_pair(
				make_pair(
					a.first.first+cos(a.second)*b.first.first-sin(a.second)*b.first.second,
					a.first.second+sin(a.second)*b.first.first+cos(a.second)*b.first.second
				),
				a.second+b.second
			);
		},
		[](pair<pair<double,double>,double>a,pair<pair<double,double>,double>b)
		{
			return b;
		}
	);
	vector<pair<pair<double,double>,double> >A(N);
	vector<double>AL(N,1);
	vector<double>Ath(N,0);
	for(int i=0;i<N;i++)
	{
		A[i]=make_pair(make_pair(1,0),0);
	}
	P.copy(A);
	for(;Q--;)
	{
		int t;cin>>t;
		if(t==0)
		{
			int i,x;cin>>i>>x;
			i--;
			Ath[i]=x*3.14159265358979323846/180;
			P.update(i,make_pair(make_pair(AL[i]*cos(Ath[i]),AL[i]*sin(Ath[i])),Ath[i]));
		}
		else if(t==1)
		{
			int i,x;cin>>i>>x;
			i--;
			AL[i]=x;
			P.update(i,make_pair(make_pair(AL[i]*cos(Ath[i]),AL[i]*sin(Ath[i])),Ath[i]));
		}
		else
		{
			int i;cin>>i;
			pair<double,double>p=P.query(0,i).first;
			cout<<fixed<<setprecision(16)<<p.first<<" "<<p.second<<endl;
		}
	}
}
0