結果

問題 No.1226 I hate Robot Arms
ユーザー tko919tko919
提出日時 2020-08-31 00:15:16
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 468 ms / 2,000 ms
コード長 3,069 bytes
コンパイル時間 2,269 ms
コンパイル使用メモリ 180,140 KB
実行使用メモリ 12,204 KB
最終ジャッジ日時 2023-08-30 09:44:51
合計ジャッジ時間 16,300 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 122 ms
4,376 KB
testcase_03 AC 142 ms
5,208 KB
testcase_04 AC 159 ms
11,060 KB
testcase_05 AC 145 ms
11,944 KB
testcase_06 AC 381 ms
11,740 KB
testcase_07 AC 114 ms
4,384 KB
testcase_08 AC 40 ms
11,100 KB
testcase_09 AC 261 ms
5,164 KB
testcase_10 AC 31 ms
4,380 KB
testcase_11 AC 184 ms
10,852 KB
testcase_12 AC 99 ms
6,952 KB
testcase_13 AC 74 ms
11,908 KB
testcase_14 AC 318 ms
5,164 KB
testcase_15 AC 25 ms
11,328 KB
testcase_16 AC 379 ms
12,204 KB
testcase_17 AC 102 ms
5,376 KB
testcase_18 AC 68 ms
5,636 KB
testcase_19 AC 192 ms
11,364 KB
testcase_20 AC 173 ms
10,856 KB
testcase_21 AC 234 ms
10,592 KB
testcase_22 AC 389 ms
11,852 KB
testcase_23 AC 389 ms
12,004 KB
testcase_24 AC 392 ms
12,008 KB
testcase_25 AC 382 ms
12,084 KB
testcase_26 AC 395 ms
11,852 KB
testcase_27 AC 468 ms
11,892 KB
testcase_28 AC 464 ms
11,936 KB
testcase_29 AC 459 ms
12,052 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:94:15: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   94 |          auto [x,y]=seg.query(0,a);
      |               ^

ソースコード

diff #

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

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end

template<typename M,typename N=M>
struct LazySegmentTree{
   using F=function<M(M,M)>; using G=function<M(M,N)>; using H=function<N(N,N)>;
   int sz,height; vector<M> data; vector<N> lazy;
   const F f;const G g; const H h; const M m1; const N n1;
   LazySegmentTree(int n,const F f,const G g,const H h,const M &m1,const N n1):f(f),g(g),h(h),m1(m1),n1(n1){
      sz=1,height=0; while(sz<n)sz<<=1,height++;
      data.assign(2*sz,m1); lazy.assign(2*sz,n1);
   }
   void build(vector<M> v){
      rep(i,0,v.size())data[i+sz]=v[i];
      for(int k=sz-1;k>0;k--)data[k]=f(data[2*k],data[2*k+1]);
   }
   M ref(int k){return lazy[k]==n1?data[k]:g(data[k],lazy[k]);}
   void recalc(int k){while(k>>=1)data[k]=f(ref(2*k),ref(2*k+1));}
   void thrust(int k){for(int i=height;i>0;i--)eval(k>>i);}
   void eval(int k){
      if(lazy[k]!=n1){
         lazy[2*k]=h(lazy[2*k],lazy[k]); lazy[2*k+1]=h(lazy[2*k+1],lazy[k]);
         data[k]=ref(k); lazy[k]=n1;
      }
   }
   void update(int a,int b,N 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);
   }
   M query(int a,int b){
      thrust(a+=sz); thrust(b+=sz-1);
      M L=m1,R=m1;
      for(int l=a,r=b+1;l<r;l>>=1,r>>=1){
         if(l&1)L=f(L,ref(l++));
         if(r&1)R=f(ref(--r),R);
      } return f(L,R);
   }
   void update2(int a,double x){
      thrust(a+=sz);
      data[a].first*=x; data[a].second*=x;
      recalc(a);
   }
};

typedef pair<double,double> P;

int main(){
   int n,q; cin>>n>>q;

   auto ff=[&](P a,P b){
      return P(a.first+b.first,a.second+b.second);
   };
   auto gg=[&](P a,int b){
      double r=b*(M_PI/180);
      return P(a.first*cos(r)-a.second*sin(r),a.first*sin(r)+a.second*cos(r));
   };
   auto hh=[&](int a,int b){return (a+b)%360;};
   LazySegmentTree<P,int> seg(n,ff,gg,hh,{0,0},0);
   vector<int> len(n),rad(n); vector<P> tmp(n);
   rep(i,0,n){
      tmp[i]={1,0};
      len[i]=1; rad[i]=0;
   }
   seg.build(tmp);
   
   rep(i,0,q){
      int t; cin>>t;
      if(t==0){
         int a,x; cin>>a>>x; a--;
         int y=(x-rad[a]+360)%360;
         seg.update(a,n,y); rad[a]=x;
      }
      if(t==1){
         int a,x; cin>>a>>x; a--;
         seg.update2(a,x*1./len[a]);
         len[a]=x;
      }
      if(t==2){
         int a; cin>>a;
         auto [x,y]=seg.query(0,a);
         printf("%.12f %.12f\n",x,y);
      }
      /*
      rep(j,0,n){
         auto [x,y]=seg.query(j,j+1);
         printf("{%.6f %.6f} ",x,y);
      } cerr<<'\n'; */
   }
   return 0;
}
0