結果

問題 No.1226 I hate Robot Arms
ユーザー motmot
提出日時 2020-09-12 02:58:26
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 4,853 bytes
コンパイル時間 1,584 ms
コンパイル使用メモリ 103,036 KB
実行使用メモリ 55,164 KB
最終ジャッジ日時 2024-06-10 11:35:47
合計ジャッジ時間 19,518 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
52,752 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const long double PI=2*asin(1);

struct SegmentTree {
  vector<tuple<long double, long double, long double> > Tree[20];

  void init() {
    for(int i=0;i<20;++i) Tree[i].resize((1<<i));
  }

  void eval(int pos1, int pos2) {
    if(get<2>(Tree[pos1][pos2])==0) return;
    long double x, y, theta, tmp;
    if(pos1+1<20) {
      x = get<0>(Tree[pos1+1][2*pos2]);
      y = get<1>(Tree[pos1+1][2*pos2]);
      theta = get<2>(Tree[pos1+1][2*pos2]);
      Tree[pos1+1][2*pos2] = mt(x, y, theta+get<2>(Tree[pos1][pos2]));
      x = get<0>(Tree[pos1+1][2*pos2+1]);
      y = get<1>(Tree[pos1+1][2*pos2+1]);
      theta = get<2>(Tree[pos1+1][2*pos2+1]);
      Tree[pos1+1][2*pos2+1] = mt(x, y, theta+get<2>(Tree[pos1][pos2]));
    }
    x = get<0>(Tree[pos1][pos2]);
    y = get<1>(Tree[pos1][pos2]);
    tmp = atan(y/x);
    theta = get<2>(Tree[pos1][pos2]);
    long double length = sqrt(x*x+y*y);
    x = length*cos(theta+tmp);
    y = length*sin(theta+tmp);
    theta = 0;
    Tree[pos1][pos2] = mt(x, y, theta);
    return;
  }

  void update(int index, long double x, long double y) {
    Tree[19][index] = mt(x, y, 0);
    index /= 2;
    long double x1, y1, x2, y2;
    for(int i=18;i>=0;--i) {
      x1 = get<0>(Tree[i+1][2*index]);
      y1 = get<1>(Tree[i+1][2*index]);
      x2 = get<0>(Tree[i+1][2*index+1]);
      y2 = get<1>(Tree[i+1][2*index+1]);
      Tree[i][index] = mt(x1+x2, y1+y2, 0);
      index /= 2;
    }
    return;
  }

  void thetaupdate(int ql, int qr, long double theta, int pos1=0, int pos2=0, int sl=0, int sr=(1<<19)) {
    eval(pos1, pos2);
    if(sr<=ql || qr<=sl) return;
    if(ql<=sl && sr<=qr) {
      long double x, y, tmp;
      x = get<0>(Tree[pos1][pos2]);
      y = get<1>(Tree[pos1][pos2]);
      tmp = get<2>(Tree[pos1][pos2]);
      tmp += theta;
      Tree[pos1][pos2] = mt(x, y, tmp);
      eval(pos1, pos2);
      return;
    }
    thetaupdate(ql, qr, theta, pos1+1, 2*pos2, sl, (sl+sr)/2);
    thetaupdate(ql, qr, theta, pos1+1, 2*pos2+1, (sl+sr)/2, sr);
    long double x1, x2, y1, y2, tmptheta;
    x1 = get<0>(Tree[pos1+1][2*pos2]);
    y1 = get<1>(Tree[pos1+1][2*pos2]);
    x2 = get<0>(Tree[pos1+1][2*pos2+1]);
    y2 = get<1>(Tree[pos1+1][2*pos2+1]);
    tmptheta = get<2>(Tree[pos1][pos2]);
    Tree[pos1][pos2] = mt(x1+x2, y1+y2, tmptheta);
    return;
  }

  void lengthupdate(int index, long double length) {
    long double x, y, tmp, theta;
    x = get<0>(Tree[19][index]);
    y = get<1>(Tree[19][index]);
    theta = get<2>(Tree[19][index]);
    tmp = sqrtl(x*x+y*y);
    x *= length/tmp;
    y *= length/tmp;
    Tree[19][index] = mt(x, y, theta);
    index /= 2;
    long double x1, x2, y1, y2;
    for(int i=18;i>=0;--i) {
      x1 = get<0>(Tree[i+1][2*index]);
      y1 = get<1>(Tree[i+1][2*index]);
      x2 = get<0>(Tree[i+1][2*index+1]);
      y2 = get<1>(Tree[i+1][2*index+1]);
      theta = get<2>(Tree[i][index]);
      Tree[i][index] = mt(x1+x2, y1+y2, theta);
      index /= 2;
    }
    return;
  }

  pair<long double, long double> getans(int ql, int qr, int pos1=0, int pos2=0, int sl=0, int sr=(1<<19)) {
    eval(pos1, pos2);
    if(sr<=ql || qr<=sl) return mp(0, 0);
    if(ql<=sl && sr<=qr) return mp(get<0>(Tree[pos1][pos2]), get<1>(Tree[pos1][pos2]));
    pair<long double, long double> ans1, ans2;
    ans1 = getans(ql, qr, pos1+1, 2*pos2, sl, (sl+sr)/2);
    ans2 = getans(ql, qr, pos1+1, 2*pos2+1, (sl+sr)/2, sr);
    return mp(ans1.fi+ans2.fi, ans1.se+ans2.se);
  }

  void check() {
    for(int i=16;i<20;++i) {
      for(int j=0;j<(1<<(i-16));++j) {
        cout<<"("<<get<0>(Tree[i][j])<<","<<get<1>(Tree[i][j])<<" "<<get<2>(Tree[i][j])<<") ";
      }
      cout<<endl;
    }
  }
};

int main() {
  int N, Q;
  cin>>N>>Q;
  SegmentTree tree; tree.init();
  for(int i=0;i<N;++i) {
    tree.update(i, 1, 0);
  }
  int query, index;
  long double x;
  vector<pair<long double, long double> > ans;
  pair<long double, long double> state;
  long double xx, yy;
  long double length;
  for(int i=0;i<Q;++i) {
    cin>>query;
    if(query==0) {
      cin>>index>>x;
      index--;
      tree.thetaupdate(index, N, x*PI/180);
    }
    else if(query==1) {
      cin>>index>>x;
      index--;
      tree.lengthupdate(index,  x);
    }
    else {
      cin>>index;
      ans.push_back(tree.getans(0, index));
    }
    //tree.check();
  }
  for(int i=0;i<ans.size();++i) cout<<fixed<<setprecision(20)<<ans[i].fi<<" "<<ans[i].se<<endl;
}

0