結果
| 問題 |
No.1226 I hate Robot Arms
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2020-09-12 22:29:39 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 149 ms / 2,000 ms |
| コード長 | 2,796 bytes |
| コンパイル時間 | 1,138 ms |
| コンパイル使用メモリ | 96,320 KB |
| 実行使用メモリ | 10,180 KB |
| 最終ジャッジ日時 | 2025-01-02 14:44:15 |
| 合計ジャッジ時間 | 6,090 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 28 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:111:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
111 | scanf("%d%d", &n, &q);
| ~~~~~^~~~~~~~~~~~~~~~
main.cpp:120:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
120 | scanf("%d%d", &op, &i);
| ~~~~~^~~~~~~~~~~~~~~~~
main.cpp:125:12: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
125 | scanf("%d", &x);
| ~~~~~^~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-
*
* 1226.cc: No.1226 I hate Robot Arms - yukicoder
*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
/* constant */
const int MAX_N = 100000;
const int MAX_E2 = 1 << 18; // = 262144
const double PI = acos(-1.0);
/* typedef */
static double cs[360], ss[360];
struct Elm {
double x, y;
int l, deg;
Elm(): x(1.0), y(0.0), l(1), deg(0) {}
Elm(double _x, double _y, int _l, int _deg):
x(_x), y(_y), l(_l), deg(_deg) {}
void _set() { x = l * cs[deg], y = l * ss[deg]; }
void setdeg(int _deg) { deg = _deg; _set(); }
void setl(int _l) { l = _l, _set(); }
Elm operator+(const Elm &e) const {
double dx = cs[deg] * e.x - ss[deg] * e.y;
double dy = ss[deg] * e.x + cs[deg] * e.y;
return Elm(x + dx, y + dy, 0.0, (deg + e.deg) % 360);
}
};
template <typename T, const int MAX_E2>
struct SegTreeAdd {
int e2;
T nodes[MAX_E2], defv;
SegTreeAdd() {}
void init(int n, T _defv) {
defv = _defv;
for (e2 = 1; e2 < n; e2 <<= 1);
fill(nodes, nodes + MAX_E2, defv);
}
T &get(int i) { return nodes[e2 - 1 + i]; }
void seti(int i, T v) { get(i) = v; }
void setall() {
for (int j = e2 - 2; j >= 0; j--)
nodes[j] = nodes[j * 2 + 1] + nodes[j * 2 + 2];
}
void set(int i, T v) {
int j = e2 - 1 + i;
nodes[j] = v;
while (j > 0) {
j = (j - 1) / 2;
nodes[j] = nodes[j * 2 + 1] + nodes[j * 2 + 2];
}
}
T add_range(int r0, int r1, int k, int i0, int i1) {
if (r1 <= i0 || i1 <= r0) return defv;
if (r0 <= i0 && i1 <= r1) return nodes[k];
int im = (i0 + i1) / 2;
T v0 = add_range(r0, r1, k * 2 + 1, i0, im);
T v1 = add_range(r0, r1, k * 2 + 2, im, i1);
return v0 + v1;
}
T add_range(int r0, int r1) { return add_range(r0, r1, 0, 0, e2); }
};
/* global variables */
SegTreeAdd<Elm,MAX_E2> st;
/* subroutines */
/* main */
int main() {
for (int i = 0; i < 360; i++) {
double th = PI * i / 180;
cs[i] = cos(th), ss[i] = sin(th);
}
int n, q;
scanf("%d%d", &n, &q);
Elm e0(0.0, 0.0, 0, 0), e1(1.0, 0.0, 1, 0);
st.init(n, e0);
for (int i = 0; i < n; i++) st.seti(i, e1);
st.setall();
while (q--) {
int op, i;
scanf("%d%d", &op, &i);
i--;
if (op == 0 || op == 1) {
int x;
scanf("%d", &x);
Elm e = st.get(i);
if (op == 0) e.setdeg(x);
else e.setl(x);
st.set(i, e);
}
else {
Elm e = st.add_range(0, i + 1);
printf("%.9lf %.9lf\n", e.x, e.y);
}
}
return 0;
}
tnakao0123