結果
| 問題 |
No.1226 I hate Robot Arms
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-04-30 05:33:19 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 299 ms / 2,000 ms |
| コード長 | 3,815 bytes |
| コンパイル時間 | 1,665 ms |
| コンパイル使用メモリ | 139,804 KB |
| 最終ジャッジ日時 | 2025-01-29 00:48:05 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 28 |
ソースコード
#pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <sstream>
#include <utility>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <array>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
return (ull)rng() % B;
}
inline double time() {
return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}
struct point{
long double x,y;
point() {}
point(long double x,long double y): x(x), y(y) {}
point& operator-=(const point &p){
x -= p.x; y -= p.y;
return *this;
}
point& operator+=(const point &p){
x += p.x; y += p.y;
return *this;
}
point& operator*=(long double d){
x *= d; y *= d;
return *this;
}
point& operator/=(long double d){
x /= d; y /= d;
return *this;
}
const point operator+ (const point& p) const;
const point operator- (const point& p) const;
const point operator* (long double d) const;
const point operator/ (long double d) const;
};
const point point::operator+ (const point& p) const{
point res(*this); return res += p;
}
const point point::operator- (const point& p) const{
point res(*this); return res -= p;
}
const point point::operator* (long double d) const{
point res(*this); return res *= d;
}
const point point::operator/ (long double d) const{
point res(*this); return res /= d;
}
long double abs(point P){
return sqrt(P.x*P.x+P.y*P.y);
}
template <class S, S (*op)(S, S), S (*e)()>
struct segtree {
int n;
vector<S> tree;
segtree() : segtree(0) {}
segtree(int n) : n(n), tree(vector<S>(n<<1, e())) {}
void update(int k) { tree[k] = op(tree[k<<1|0], tree[k<<1|1]); }
S operator[](int i) {return tree[i+n]; }
void set(int i, S x) {
i += n;
tree[i] = x;
while(i >>= 1) {
update(i);
}
}
// [l,r)
S query(int l, int r) {
S sml = e(), smr = e();
for(l += n, r += n; l < r; l >>= 1, r >>= 1){
if(l & 1) sml = op(sml, tree[l++]);
if(r & 1) smr = op(tree[--r], smr);
}
return op(sml,smr);
}
};
// ベクトルと回転角度を持つ
using P = pair<point,long double>;
P op(P a,P b){
auto p = a.first;
auto pp = b.first;
p += point(pp.x*cos(a.second)-pp.y*sin(a.second), pp.x*sin(a.second)+pp.y*cos(a.second));
return {p, a.second+b.second};
}
P e() {return {{0,0},0};};
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n,q; cin >> n >> q;
segtree<P,op,e> seg(n);
for(int i=0;i<n;i++){
seg.set(i, {{1,0},0});
}
while(q--){
int type; cin >> type;
int i; cin >> i; i--;
auto P = seg[i];
auto &p = P.first;
if(type == 1){
int w; cin >> w;
p = p / abs(p) * w;
seg.set(i, P);
}
else if(type == 0){
int w; cin >> w;
long double theta = acos(-1.0L) * (w) / 180.0;
p = {p.x*cos(-P.second+theta)-p.y*sin(-P.second+theta), p.x*sin(-P.second+theta)+p.y*cos(-P.second+theta)};
P.second = theta;
seg.set(i, P);
}
else{
auto res = seg.query(0, i+1);
double x = res.first.x, y = res.first.y;
printf("%.9f %.9f\n",x, y);
}
}
}