結果

問題 No.1226 I hate Robot Arms
ユーザー leaf_1415leaf_1415
提出日時 2020-09-11 21:51:07
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 3,068 bytes
コンパイル時間 3,929 ms
コンパイル使用メモリ 93,204 KB
実行使用メモリ 11,252 KB
最終ジャッジ日時 2023-08-30 09:48:54
合計ジャッジ時間 13,989 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
9,376 KB
testcase_01 AC 6 ms
9,300 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 442 ms
11,156 KB
testcase_28 AC 437 ms
11,224 KB
testcase_29 AC 472 ms
11,188 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<double, double> P;

// range-add, range-min query

P sum(P &a, P &b)
{
	return P(a.first+b.first, a.second+b.second);
}
P rot(P &p, double a)
{
	return P(p.first*cos(a) - p.second*sin(a), p.first*sin(a) + p.second*cos(a));
}
 
struct LazySegTree{
	int size;
	vector<P> seg;
	vector<double> delay;
	
	LazySegTree(){}
	LazySegTree(int size){
		this->size = size;
		seg.resize(1<<(size+1));
		delay.resize(1<<(size+1));
	}
	
	void init()
	{
		for(int i = 0; i < (1<<(size+1)); i++){
			seg[i] = P(0, 0);
			delay[i] = 0;
		}
	}
	
	void eval(int l, int r, int k)
	{
		if(fabs(delay[k]) > 1e-9){
			seg[k] = rot(seg[k], delay[k]);
			if(l < r){
				delay[k*2] += delay[k];
				delay[k*2+1] += delay[k];
			}
			delay[k] = 0;
		}
	}
	
	void update(int i, P val)
	{
		int l = 0, r = (1<<size)-1, k = 1;
		eval(l, r, k);
		for(int j = size-1; j >= 0; j--){
			k <<= 1;
			if(i & (1<<j)){
				k++;
				r = (l+r)/2;
			}
			else l = (l+r)/2+1;
			eval(l, r, k);
		}
		
		i += (1 << size);
		seg[i] = val;
		while(i > 1){
			i /= 2;
			seg[i] = sum(seg[i*2], seg[i*2+1]);
		}
	}
	
	void add(int a, int b, int k, int l, int r, double val)
	{
		eval(l, r, k);
		
		if(b < l || r < a) return;
		if(a <= l && r <= b){
			delay[k] += val;
			eval(l, r, k);
			return;
		}
		add(a, b, k*2, l, (l+r)/2, val);
		add(a, b, k*2+1, (l+r)/2+1, r, val);
		seg[k] = sum(seg[k*2], seg[k*2+1]);
	}
	void add(int a, int b, double val){
		if(a > b) return;
		add(a, b, 1, 0, (1<<size)-1, val);
	}
 
	P query(int a, int b, int k, int l, int r)
	{
		eval(l, r, k);
		
		if(b < l || r < a) return P(0, 0);
		if(a <= l && r <= b) return seg[k];
		P lval = query(a, b, k*2, l, (l+r)/2);
		P rval = query(a, b, k*2+1, (l+r)/2+1, r);
		return sum(lval, rval);
	}
	P query(int a, int b)
	{
		return query(a, b, 1, 0, (1<<size)-1);
	}
};

llint n, Q;
LazySegTree seg(17);
double d[100005], ang[100005];

int main(void)
{
	//ios::sync_with_stdio(0);
	//cin.tie(0);
	
	cin >> n >> Q;
	
	seg.init();
	for(int i = 1; i <= n; i++){
		d[i] = 1, ang[i] = 0;
		seg.update(i, P(1, 0));
	}
	
	llint t, id, x;
	for(int i = 1; i <= Q; i++){
		cin >> t;
		if(t == 0){
			cin >> id >> x;
			double a = x * M_PI / 180;
			seg.add(id, n, a - ang[id]);
			ang[id] = a;
		}
		if(t == 1){
			cin >> id >> x;
			P res = seg.query(id, id);
			res.first *= x / d[id], res.second *= x / d[id];
			seg.update(id, res);
		}
		if(t == 2){
			cin >> id;
			P res = seg.query(1, id);
			printf("%.11f %.11f\n", res.first, res.second);
		}
	}
	
	return 0;
}
0