結果

問題 No.1226 I hate Robot Arms
ユーザー kyoprounokyoprouno
提出日時 2020-09-12 00:43:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 440 ms / 2,000 ms
コード長 2,984 bytes
コンパイル時間 2,451 ms
コンパイル使用メモリ 179,852 KB
実行使用メモリ 14,528 KB
最終ジャッジ日時 2023-08-30 11:19:01
合計ジャッジ時間 20,659 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 123 ms
4,696 KB
testcase_03 AC 139 ms
6,012 KB
testcase_04 AC 150 ms
13,596 KB
testcase_05 AC 131 ms
14,156 KB
testcase_06 AC 350 ms
13,884 KB
testcase_07 AC 112 ms
4,872 KB
testcase_08 AC 37 ms
13,664 KB
testcase_09 AC 257 ms
5,980 KB
testcase_10 AC 31 ms
4,380 KB
testcase_11 AC 169 ms
13,464 KB
testcase_12 AC 92 ms
8,216 KB
testcase_13 AC 68 ms
14,312 KB
testcase_14 AC 311 ms
5,912 KB
testcase_15 AC 24 ms
14,044 KB
testcase_16 AC 343 ms
14,488 KB
testcase_17 AC 97 ms
5,912 KB
testcase_18 AC 65 ms
6,348 KB
testcase_19 AC 171 ms
14,140 KB
testcase_20 AC 157 ms
13,852 KB
testcase_21 AC 215 ms
13,672 KB
testcase_22 AC 352 ms
14,416 KB
testcase_23 AC 355 ms
14,528 KB
testcase_24 AC 359 ms
14,460 KB
testcase_25 AC 358 ms
14,464 KB
testcase_26 AC 357 ms
14,416 KB
testcase_27 AC 435 ms
14,392 KB
testcase_28 AC 440 ms
14,456 KB
testcase_29 AC 434 ms
14,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

template <typename T>
struct SegmentTree{
  using F = function<T(T,T)>;
  int n;
  F f;
  T ti;
  vector<T> dat;

  SegmentTree(){}
  SegmentTree(F f,T ti):f(f),ti(ti){}

  void init(int n_){
    n=1;
    while(n<n_) n<<=1;
    dat.assign(n<<1,ti);
  }

  void build(const vector<T> &v){
    int n_=v.size();
    init(n_);
    for(int i=0;i<n_;i++) dat[n+i]=v[i];
    for(int i=n-1;i;i--)
      dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
  }

  void set_val(int k,T x){
    dat[k+=n]=x;
    while(k>>=1)
      dat[k]=f(dat[(k<<1)|0],dat[(k<<1)|1]);
  }

  T query(int a,int b){
    if(a>=b) return ti;
    T vl=ti,vr=ti;
    for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1) {
      if(l&1) vl=f(vl,dat[l++]);
      if(r&1) vr=f(dat[--r],vr);
    }
    return f(vl,vr);
  }

  template<typename C>
  int find(int st,C &check,T &acc,int k,int l,int r){
    if(l+1==r){
      acc=f(acc,dat[k]);
      return check(acc)?k-n:-1;
    }
    int m=(l+r)>>1;
    if(m<=st) return find(st,check,acc,(k<<1)|1,m,r);
    if(st<=l&&!check(f(acc,dat[k]))){
      acc=f(acc,dat[k]);
      return -1;
    }
    int vl=find(st,check,acc,(k<<1)|0,l,m);
    if(~vl) return vl;
    return find(st,check,acc,(k<<1)|1,m,r);
  }

  template<typename C>
  int find(int st,C &check){
    T acc=ti;
    return find(st,check,acc,1,0,n);
  }
};




//INSERT ABOVE HERE
int main(){
  
  using D = double;
  struct T{
    D x,y,theta,sum;
    T(D x,D y,D theta,D sum):x(x),y(y),theta(theta),sum(sum){}
  };

  T ti(0,0,-1,0);
  auto f=[&](T a,T b){
    if(a.theta<0) return b;
    D th=a.sum+b.theta;
    D nx=a.x+(cos(th)*b.x-sin(th)*b.y);
    D ny=a.y+(sin(th)*b.x+cos(th)*b.y);
    return T(nx,ny,a.theta,a.sum+b.theta+b.sum);
  };
  SegmentTree<T> seg(f,ti);

  int n,q;
  cin>>n>>q;
  cout << setprecision(30) << fixed;
  vector<T> vt(n,T(1,0,0,0));
  seg.build(vt);
  const D pi = asin(1) * 2;

  auto print=[&](T res){
    // cout<<":"<<res.x<<' '<<res.y<<' '<<res.theta<<endl;
    cout<<cos(res.theta)*res.x-sin(res.theta)*res.y<<' ';
    cout<<sin(res.theta)*res.x+cos(res.theta)*res.y<<endl;
  };

  for(int j=0;j<q;j++){
    int t;
    cin>>t;
    if(t==0){
      int i,x;
      cin>>i>>x;
      i--;
      vt[i].theta=x*pi/180.0;
      seg.set_val(i,vt[i]);
    }
    if(t==1){
      int i,x;
      cin>>i>>x;
      i--;
      D len=hypot(vt[i].x,vt[i].y);
      vt[i].x*=x/len;
      vt[i].y*=x/len;
      seg.set_val(i,vt[i]);
    }
    if(t==2){
      int i;
      cin>>i;
      print(seg.query(0,i));
    }
  }
  return 0;
}
0