結果

問題 No.1226 I hate Robot Arms
ユーザー leaf_1415leaf_1415
提出日時 2020-09-11 21:53:39
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,130 ms / 2,000 ms
コード長 3,163 bytes
コンパイル時間 1,673 ms
コンパイル使用メモリ 94,528 KB
実行使用メモリ 19,044 KB
最終ジャッジ日時 2023-08-30 09:50:51
合計ジャッジ時間 26,342 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
15,440 KB
testcase_01 AC 12 ms
15,376 KB
testcase_02 AC 314 ms
15,648 KB
testcase_03 AC 389 ms
15,960 KB
testcase_04 AC 426 ms
17,972 KB
testcase_05 AC 382 ms
18,392 KB
testcase_06 AC 1,005 ms
18,120 KB
testcase_07 AC 299 ms
15,836 KB
testcase_08 AC 112 ms
17,880 KB
testcase_09 AC 709 ms
16,028 KB
testcase_10 AC 84 ms
15,816 KB
testcase_11 AC 489 ms
17,552 KB
testcase_12 AC 266 ms
16,440 KB
testcase_13 AC 205 ms
18,340 KB
testcase_14 AC 817 ms
16,484 KB
testcase_15 AC 72 ms
18,096 KB
testcase_16 AC 1,000 ms
18,580 KB
testcase_17 AC 275 ms
16,280 KB
testcase_18 AC 180 ms
16,824 KB
testcase_19 AC 502 ms
17,816 KB
testcase_20 AC 455 ms
17,548 KB
testcase_21 AC 612 ms
17,884 KB
testcase_22 AC 1,024 ms
19,044 KB
testcase_23 AC 1,041 ms
18,940 KB
testcase_24 AC 1,029 ms
18,944 KB
testcase_25 AC 1,034 ms
19,000 KB
testcase_26 AC 1,022 ms
18,296 KB
testcase_27 AC 1,130 ms
18,924 KB
testcase_28 AC 1,122 ms
18,936 KB
testcase_29 AC 1,124 ms
18,288 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 double long double
#define PI 3.1415926535897932384626433832795028841971
#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 * 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);
			d[id] = x;
		}
		if(t == 2){
			cin >> id;
			P res = seg.query(1, id);
			printf("%.11Lf %.11Lf\n", res.first, res.second);
		}
	}
	
	return 0;
}
0