結果

問題 No.1226 I hate Robot Arms
ユーザー chocoruskchocorusk
提出日時 2020-09-11 21:54:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 417 ms / 2,000 ms
コード長 3,026 bytes
コンパイル時間 1,625 ms
コンパイル使用メモリ 141,444 KB
実行使用メモリ 14,924 KB
最終ジャッジ日時 2023-08-30 09:50:01
合計ジャッジ時間 14,549 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 115 ms
4,592 KB
testcase_03 AC 138 ms
5,980 KB
testcase_04 AC 156 ms
13,576 KB
testcase_05 AC 141 ms
14,160 KB
testcase_06 AC 363 ms
14,192 KB
testcase_07 AC 107 ms
5,100 KB
testcase_08 AC 38 ms
13,664 KB
testcase_09 AC 245 ms
5,720 KB
testcase_10 AC 30 ms
4,384 KB
testcase_11 AC 170 ms
13,504 KB
testcase_12 AC 94 ms
8,296 KB
testcase_13 AC 69 ms
14,188 KB
testcase_14 AC 300 ms
5,928 KB
testcase_15 AC 24 ms
13,936 KB
testcase_16 AC 354 ms
14,240 KB
testcase_17 AC 97 ms
6,200 KB
testcase_18 AC 64 ms
6,500 KB
testcase_19 AC 173 ms
14,108 KB
testcase_20 AC 165 ms
13,560 KB
testcase_21 AC 225 ms
13,572 KB
testcase_22 AC 365 ms
14,460 KB
testcase_23 AC 369 ms
14,760 KB
testcase_24 AC 380 ms
14,872 KB
testcase_25 AC 369 ms
14,780 KB
testcase_26 AC 365 ms
14,808 KB
testcase_27 AC 413 ms
14,784 KB
testcase_28 AC 417 ms
14,692 KB
testcase_29 AC 415 ms
14,924 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
template<typename Monoid, typename OperatorMonoid=Monoid>
struct LazySegmentTree{
	using F=function<Monoid(Monoid, Monoid)>;
	using G=function<Monoid(Monoid, OperatorMonoid, int)>;
	using H=function<OperatorMonoid(OperatorMonoid, OperatorMonoid)>;
	int sz;
	vector<Monoid> data;
	vector<OperatorMonoid> lazy;
	const F f;
	const G g;
	const H h;
	const Monoid e1;
	const OperatorMonoid e0;

	LazySegmentTree(int n, const F f, const G g, const H h, const Monoid &e1, const OperatorMonoid &e0): f(f), g(g), h(h), e1(e1), e0(e0){
		sz=1;
		while(sz<n) sz<<=1;
		data.resize(2*sz-1, e1);
		lazy.resize(2*sz-1, e0);
	}

	void build(vector<Monoid> v){
		for(int i=0; i<v.size(); i++) data[i+sz-1]=v[i];
		for(int i=sz-2; i>=0; i--) data[i]=f(data[2*i+1], data[2*i+2]);
	}

	void eval(int k, int l, int r){
		if(lazy[k]!=e0){
			data[k]=g(data[k], lazy[k], r-l);
			if(k<sz-1){
				lazy[2*k+1]=h(lazy[2*k+1], lazy[k]);
				lazy[2*k+2]=h(lazy[2*k+2], lazy[k]);
			}
		}
		lazy[k]=e0;
	}

	void update(int a, int b, const OperatorMonoid &x, int k, int l, int r){
		eval(k, l, r);
		if(r<=a || b<=l) return;
		if(a<=l && r<=b){
			lazy[k]=h(lazy[k], x);
			eval(k, l, r);
		}else{
			update(a, b, x, 2*k+1, l, (l+r)/2);
			update(a, b, x, 2*k+2, (l+r)/2, r);
			data[k]=f(data[2*k+1], data[2*k+2]);
		}
	}
	void update(int a, int b, const OperatorMonoid &x){
		return update(a, b, x, 0, 0, sz);
	}

	Monoid find(int a, int b, int k, int l, int r){
		eval(k, l, r);
		if(b<=l || r<=a) return e1;
		if(a<=l && r<=b) return data[k];
		else return f(find(a, b, 2*k+1, l, (l+r)/2), find(a, b, 2*k+2, (l+r)/2, r));
	}
	Monoid find(int a, int b){
		return find(a, b, 0, 0, sz);
	}
	Monoid operator[](const int &k){
		return find(k, k+1);
	}
};
int main()
{
	int n, q;
	cin>>n>>q;
	using C=complex<double>;
	auto f=[](C a, C b){
		return a+b;
	};
	auto g=[](C a, C x, int len){
		return a*x;
	};
	auto h=[](C x, C y){
		return x*y;
	};
	vector<C> v(n, C(1, 0));
	LazySegmentTree<C> seg(n, f, g, h, C(0, 0), C(1, 0));
	seg.build(v);
	double d[100010];
	fill(d, d+n, 1);
	double c[100010];
	fill(c, c+n, 0);
	const double PI=acos(-1.0);
	while(q--){
		int t;
		cin>>t;
		if(t==0){
			int i, x; cin>>i>>x;
			i--;
			seg.update(i, n, polar(1.0, PI/180*(x-c[i])));
			c[i]=x;
		}else if(t==1){
			int i, x; cin>>i>>x;
			i--;
			seg.update(i, i+1, C(x/d[i], 0));
			d[i]=x;
		}else{
			int i; cin>>i;
			C ans=seg.find(0, i);
			printf("%.7lf %.7lf\n", ans.real(), ans.imag());
		}
	}
	return 0;
}
0