結果
| 問題 |
No.1226 I hate Robot Arms
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-01-07 18:46:29 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 5,257 bytes |
| コンパイル時間 | 2,270 ms |
| コンパイル使用メモリ | 144,884 KB |
| 最終ジャッジ日時 | 2025-01-17 10:16:31 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | WA * 28 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
using namespace std;
using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;
template<class T>
inline bool chmax(T& x, T y){
if(x < y){
x = y;
return true;
}
return false;
}
template<class T>
inline bool chmin(T& x, T y){
if(x > y){
x = y;
return true;
}
return false;
}
template<typename Monoid, typename OperatorMonoid = Monoid>
struct LazySegmentTree{
using F = function<Monoid(Monoid, Monoid)>;
using G = function<Monoid(Monoid, OperatorMonoid)>;
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 M1; // モノイドの単位元
const OperatorMonoid OM0; // 作用素モノイドの単位元
LazySegmentTree(int n, const F f, const G g, const H h, const Monoid &M1, const OperatorMonoid OM0)
: f(f), g(g), h(h), M1(M1), OM0(OM0)
{
sz = 1;
while(sz < n) sz <<= 1;
data.assign(sz << 1, M1);
lazy.assign(sz << 1, OM0);
}
void set(int k, const Monoid &x){
data[k + sz] = x;
}
void build(){
for(int k = sz - 1; k > 0; --k){
data[k] = f(data[k << 1], data[k << 1 | 1]);
}
}
void propagate(int k){
if(lazy[k] != OM0){
if(k < sz){
lazy[k << 1] = h(lazy[k << 1], lazy[k]);
lazy[k << 1 | 1] = h(lazy[k << 1 | 1], lazy[k]);
}
data[k] = g(data[k], lazy[k]);
lazy[k] = OM0;
}
}
Monoid update(int a, int b, const OperatorMonoid &x, int k = 1, int l = 0, int r = -1){
if(r == -1) r = sz;
propagate(k);
if(r <= a || b <= l) return data[k];
else if(a <= l && r <= b){
lazy[k] = h(lazy[k], x);
propagate(k);
return data[k];
}
else{
return data[k] = f(update(a, b, x, k << 1, l, (l + r) >> 1),
update(a, b, x, k << 1 | 1, (l + r) >> 1, r));
}
}
Monoid query(int a, int b, int k = 1, int l = 0, int r = -1){
if(r == -1) r = sz;
propagate(k);
if(r <= a || b <= l) return M1;
else if(a <= l && r <= b) return data[k];
else{
return f(query(a, b, k << 1, l, (l + r) >> 1),
query(a, b, k << 1 | 1, (l + r) >> 1, r));
}
}
Monoid operator[](const int &k){
return query(k, k + 1);
}
};
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, Q;
cin >> N >> Q;
struct node {
double x, y;
ll d;
double theta;
node(double x = 0.0, double y = 0.0, ll d = 0, double theta = 0.0)
: x(x), y(y), d(d), theta(theta) {}
};
auto op = [](node a, node b) {
return node(a.x + b.x, a.y + b.y, a.d + b.d, a.theta + b.theta);
};
using opnode = pair<int, double>;
auto mapping = [](node a, opnode b) {
double nx = a.x * cos(b.second) - a.y * sin(b.second);
double ny = a.x * sin(b.second) + a.y * cos(b.second);
ll nd = a.d + b.first;
double ntheta = a.theta + b.second;
if(nd != a.d){
nx *= nd / a.d; nx += 1e-9;
ny *= nd / a.d; ny += 1e-9;
}
return node(nx, ny, nd, ntheta);
};
auto composition = [](opnode a, opnode b) {
return opnode(a.first + b.first, a.second + b.second);
};
LazySegmentTree<node, opnode> seg(N, op, mapping, composition, node(), opnode(0, 0.0));
for(int i = 0; i < N; ++i){
seg.set(i, node(1.0, 0.0, 1, 0.0));
}
seg.build();
// cout << "data\n";
// for(int i = 0; i < N; ++i) cout << seg[i].x << ',' << seg[i].y << '\n';
// cout << seg.query(0, N).x << ',' << seg.query(0, N).y << '\n';
const double pi = acos(-1);
cout << fixed << setprecision(10);
for(int q = 0; q < Q; ++q){
int t, i, x;
cin >> t >> i;
--i;
if(t != 2) cin >> x;
if(t == 0){
seg.update(i, N, opnode(0, x * pi / 180.0));
}
else if(t == 1){
seg.update(i, i + 1, opnode(x - seg[i].d, 0.0));
}
else{
auto res = seg.query(0, i + 1);
cout << res.x << ' ' << res.y << '\n';
}
}
// for(int i = 0; i < N; ++i){
// auto res = seg[i];
// cout << "x:" << res.x << ",y:" << res.y << ",d:" << res.d;
// cout << ",theta:" << res.theta * 180 / pi << '\n';
// }
return 0;
}