結果

問題 No.1226 I hate Robot Arms
ユーザー theory_and_metheory_and_me
提出日時 2020-09-12 00:37:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 451 ms / 2,000 ms
コード長 7,056 bytes
コンパイル時間 2,958 ms
コンパイル使用メモリ 207,288 KB
実行使用メモリ 20,568 KB
最終ジャッジ日時 2023-08-30 11:17:02
合計ジャッジ時間 19,311 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 121 ms
5,320 KB
testcase_03 AC 143 ms
8,040 KB
testcase_04 AC 161 ms
20,220 KB
testcase_05 AC 144 ms
20,368 KB
testcase_06 AC 376 ms
20,116 KB
testcase_07 AC 113 ms
6,108 KB
testcase_08 AC 42 ms
20,324 KB
testcase_09 AC 261 ms
7,976 KB
testcase_10 AC 30 ms
4,536 KB
testcase_11 AC 182 ms
20,148 KB
testcase_12 AC 100 ms
12,068 KB
testcase_13 AC 76 ms
20,284 KB
testcase_14 AC 319 ms
7,836 KB
testcase_15 AC 28 ms
20,184 KB
testcase_16 AC 372 ms
20,392 KB
testcase_17 AC 103 ms
8,048 KB
testcase_18 AC 69 ms
8,040 KB
testcase_19 AC 190 ms
20,196 KB
testcase_20 AC 171 ms
20,224 KB
testcase_21 AC 233 ms
20,268 KB
testcase_22 AC 380 ms
20,384 KB
testcase_23 AC 388 ms
20,384 KB
testcase_24 AC 383 ms
20,404 KB
testcase_25 AC 385 ms
20,344 KB
testcase_26 AC 383 ms
20,284 KB
testcase_27 AC 450 ms
20,568 KB
testcase_28 AC 445 ms
20,284 KB
testcase_29 AC 451 ms
20,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << "Line " << __LINE__ << ": " <<  #x << " = " << (x) << "\n";
#define spa << " " <<
#define fi first
#define se second
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()

using ld = long double;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;

template<typename T> using V = vector<T>;
template<typename T> using P = pair<T, T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){os << "(" << v.first << ", " << v.second << ")"; return os;}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<vector<T>> &v){ for(auto &e : v){os << e << "\n";} return os;}
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

template <class T> void UNIQUE(vector<T> &x) {sort(ALL(x));x.erase(unique(ALL(x)), x.end());}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
void fail() { cout << -1 << '\n'; exit(0); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<"\n";}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<"\n";};

const ll INF = (1ll<<62);
// const ld EPS   = 1e-10;
const ld PI    = acos(-1.0);
const ll mod = (int)1e9 + 7;
//const ll mod = 998244353;

template< typename Monoid, typename OperatorMonoid, typename F, typename G, typename H >
struct LazySegmentTree {
  // std::function は遅いので使わないことを推奨
  //using F = function< Monoid(Monoid, Monoid) >;
  //using G = function< Monoid(Monoid, OperatorMonoid) >;
  //using H = function< OperatorMonoid(OperatorMonoid, OperatorMonoid) >;

  int sz, height;
  vector< Monoid > data;
  vector< OperatorMonoid > lazy;
  const F f;
  const G g;
  const H h;
  const Monoid M1;
  const OperatorMonoid OM0;


  // n: サイズ
  // f: 二つの区間をマージする二項演算
  // g: 要素と作用素をマージする二項演算
  // h: 作用素同士をマージする二項演算
  // M1: モノイドの単位元
  // OM0: 作用素の単位元

  // 初期化を忘れない!x を初期値とすると
  // REP(i, n) seg[i].set(x);
  // seg.build();

  // 初期化なしだとM1で初期化される
  // range sum をするときは,M1は(0, 0)だが初期化は(0, 1)であることに注意!

  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;
    height = 0;
    while(sz < n) sz <<= 1, height++;
    data.assign(2 * sz, M1);
    lazy.assign(2 * sz, 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[2 * k + 0], data[2 * k + 1]);
    }
  }

  inline void propagate(int k) {
    if(lazy[k] != OM0) {
      lazy[2 * k + 0] = h(lazy[2 * k + 0], lazy[k]);
      lazy[2 * k + 1] = h(lazy[2 * k + 1], lazy[k]);
      data[k] = reflect(k);
      lazy[k] = OM0;
    }
  }

  inline Monoid reflect(int k) {
    return lazy[k] == OM0 ? data[k] : g(data[k], lazy[k]);
  }

  inline void recalc(int k) {
    while(k >>= 1) data[k] = f(reflect(2 * k + 0), reflect(2 * k + 1));
  }

  inline void thrust(int k) {
    for(int i = height; i > 0; i--) propagate(k >> i);
  }

  void update(int a, int b, const OperatorMonoid &x) {
    thrust(a += sz);
    thrust(b += sz - 1);
    for(int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
      if(l & 1) lazy[l] = h(lazy[l], x), ++l;
      if(r & 1) --r, lazy[r] = h(lazy[r], x);
    }
    recalc(a);
    recalc(b);
  }

  Monoid query(int a, int b) {
    thrust(a += sz);
    thrust(b += sz - 1);
    Monoid L = M1, R = M1;
    for(int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
      if(l & 1) L = f(L, reflect(l++));
      if(r & 1) R = f(reflect(--r), R);
    }
    return f(L, R);
  }

  Monoid operator[](const int &k) {
    return query(k, k + 1);
  }

  template< typename C >
  int find_subtree(int a, const C &check, Monoid &M, bool type) {
    while(a < sz) {
      propagate(a);
      Monoid nxt = type ? f(reflect(2 * a + type), M) : f(M, reflect(2 * a + type));
      if(check(nxt)) a = 2 * a + type;
      else M = nxt, a = 2 * a + 1 - type;
    }
    return a - sz;
  }

  template< typename C >
  int find_first(int a, const C &check) {
    Monoid L = M1;
    if(a <= 0) {
      if(check(f(L, reflect(1)))) return find_subtree(1, check, L, false);
      return -1;
    }
    thrust(a + sz);
    int b = sz;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) {
        Monoid nxt = f(L, reflect(a));
        if(check(nxt)) return find_subtree(a, check, L, false);
        L = nxt;
        ++a;
      }
    }
    return -1;
  }


  template< typename C >
  int find_last(int b, const C &check) {
    Monoid R = M1;
    if(b >= sz) {
      if(check(f(reflect(1), R))) return find_subtree(1, check, R, true);
      return -1;
    }
    thrust(b + sz - 1);
    int a = sz;
    for(b += sz; a < b; a >>= 1, b >>= 1) {
      if(b & 1) {
        Monoid nxt = f(reflect(--b), R);
        if(check(nxt)) return find_subtree(b, check, R, true);
        R = nxt;
      }
    }
    return -1;
  }
};

using cld = complex<ld>; 

int main(){

    ll N, Q;
    cin >> N >> Q;

    auto f = [](cld x, cld y){return x+y;};
    auto g = [](cld x, cld a){return x*a;};
    auto h = [](cld a, cld b){return a*b;};
    cld M1 = 0;
    cld OM0 = 1.0;
    LazySegmentTree<cld, cld, decltype(f), decltype(g), decltype(h)> seg(N, f, g, h, M1, OM0);
    REP(i, N) seg.set(i, 1.0);
    seg.build();

    V<ll> theta(N, 0);
    while(Q--){
        ll t;
        cin >> t;
        if(t==0){
            ll i, x;
            cin >> i >> x;
            i--;
            seg.update(i, N, polar((ld)1.0, (x-theta[i])*PI/180));
            theta[i] = x;
        }else if(t==1){
            ll i, x;
            cin >> i >> x;
            i--;
            auto now = seg.query(i, i+1);
            seg.update(i, i+1, abs(x)/abs(now));
        }else{
            ll i;
            cin >> i;
            cld res = seg.query(0, i);
            cout << real(res) spa imag(res) << endl;
        }
    }

    return 0;
}
0