結果
| 問題 |
No.1226 I hate Robot Arms
|
| コンテスト | |
| ユーザー |
Nachia
|
| 提出日時 | 2020-09-28 19:44:16 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 295 ms / 2,000 ms |
| コード長 | 2,923 bytes |
| コンパイル時間 | 1,905 ms |
| コンパイル使用メモリ | 175,796 KB |
| 実行使用メモリ | 19,788 KB |
| 最終ジャッジ日時 | 2024-07-02 10:12:51 |
| 合計ジャッジ時間 | 14,451 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 28 |
ソースコード
//#include<atcoder/all>
//using namespace atcoder;
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)
template<
class S,
S(*op)(S a, S b),
S(*e)(),
class F,
S(*mapping)(F a, S b),
F(*composition)(F a, F b),
F(*id)()
>
struct lazy_segtree {
private:
struct Node { S v; F r; };
int N;
vector<Node> V;
void spread(int i) {
V[i].v = mapping(V[i].r, V[i].v);
if (i < N) {
V[i * 2].r = composition(V[i].r, V[i * 2].r);
V[i * 2 + 1].r = composition(V[i].r, V[i * 2 + 1].r);
}
V[i].r = id();
}
public:
lazy_segtree(int n) {
N = 1; while (N < n) N *= 2;
V.assign(N * 2, { e(),id() });
}
lazy_segtree(vector<S> A) {
N = 1; while (N < A.size()) N *= 2;
V.assign(N * 2, { e(),id() });
rep(i, A.size()) V[N + i].v = A[i];
for (int i = N - 1; i >= 1; i--)
V[i].v = op(V[i * 2].v, V[i * 2 + 1].v);
}
void set(int p, S v) {
p += N;
for (int d = N; d >= 1; d /= 2) spread(p / d);
V[p].v = v;
int z = 1;
while (p != 1) {
p /= 2; z *= 2;
spread(p * 2); spread(p * 2 + 1);
V[p].v = op(V[p * 2].v, V[p * 2 + 1].v);
}
}
S get(int p) {
p += N;
for (int d = N; d >= 1; d /= 2) spread(p / d);
return V[p].v;
}
void apply(int l, int r, F v, int a = 0, int b = 0, int i = -1) {
if (i == -1) { a = 0; b = N; i = 1; }
if (r <= a || b <= l) { spread(i); return; }
else if (l <= a && b <= r) { V[i].r = composition(v, V[i].r); spread(i); return; }
spread(i);
apply(l, r, v, a, (a + b) / 2, i * 2);
apply(l, r, v, (a + b) / 2, b, i * 2 + 1);
V[i].v = op(V[i * 2].v, V[i * 2 + 1].v);
}
S prod(int l, int r, int a = 0, int b = 0, int i = -1) {
if (i == -1) { a = 0; b = N; i = 1; }
if (r <= a || b <= l) return e();
spread(i);
if (l <= a && b <= r) return V[i].v;
S q1 = prod(l, r, a, (a + b) / 2, i * 2);
S q2 = prod(l, r, (a + b) / 2, b, i * 2 + 1);
q1 = op(q1, q2);
return q1;
}
};
using C = complex<double>;
struct S { C angle, len; };
S op(S l, S r) { return { l.angle * r.angle,l.len + l.angle * r.len }; }
S e() { return { C(1.,0.),C(0.,0.) }; }
struct F {};
S mapping(F f, S a) { return a; }
F composition(F f, F g) { return g; }
F id() { return {}; }
using RQ = lazy_segtree<S, op, e, F, mapping, composition, id>;
int main() {
int N, Q; cin >> N >> Q;
vector<S> A(N + 1, e()); rep(i, N) A[i + 1] = { C(1.,0.),C(1.,0.) };
RQ G(A);
double pi = acos(-1.);
cout << fixed << setprecision(10);
while (Q--) {
int c; cin >> c;
if (c == 0) {
int i, x; cin >> i >> x;
S buf = G.get(i - 1);
buf.angle = polar(1., double(x) / 180. * pi);
G.set(i - 1, buf);
}
if (c == 1) {
int i, x; cin >> i >> x;
S buf = G.get(i);
buf.len = C(double(x), 0.);
G.set(i, buf);
}
if (c == 2) {
int i; cin >> i;
S buf = G.prod(0, i + 1);
cout << buf.len.real() << " " << buf.len.imag() << endl;
}
}
return 0;
}
Nachia