結果

問題 No.3221 Count Turns
ユーザー Taiki0715
提出日時 2025-08-01 21:56:33
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 7,085 bytes
コンパイル時間 3,303 ms
コンパイル使用メモリ 291,724 KB
実行使用メモリ 15,152 KB
最終ジャッジ日時 2025-08-01 21:56:41
合計ジャッジ時間 7,550 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 6 WA * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ull=unsigned long long;
using P=pair<ll,ll>;
template<typename T>using minque=priority_queue<T,vector<T>,greater<T>>;
template<typename T>bool chmax(T &a,const T &b){return (a<b?(a=b,true):false);}
template<typename T>bool chmin(T &a,const T &b){return (a>b?(a=b,true):false);}
template<typename T1,typename T2>istream &operator>>(istream &is,pair<T1,T2>&p){is>>p.first>>p.second;return is;}
template<typename T1,typename T2,typename T3>istream &operator>>(istream &is,tuple<T1,T2,T3>&a){is>>std::get<0>(a)>>std::get<1>(a)>>std::get<2>(a);return is;}
template<typename T,size_t n>istream &operator>>(istream &is,array<T,n>&a){for(auto&i:a)is>>i;return is;}
template<typename T>istream &operator>>(istream &is,vector<T> &a){for(auto &i:a)is>>i;return is;}
template<typename T1,typename T2>void operator++(pair<T1,T2>&a,int n){a.first++,a.second++;}
template<typename T1,typename T2>void operator--(pair<T1,T2>&a,int n){a.first--,a.second--;}
template<typename T>void operator++(vector<T>&a,int n){for(auto &i:a)i++;}
template<typename T>void operator--(vector<T>&a,int n){for(auto &i:a)i--;}
#define overload3(_1,_2,_3,name,...) name
#define rep1(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define rep(...) overload3(__VA_ARGS__,rep2,rep1)(__VA_ARGS__)
#define reps(i,l,r) rep2(i,l,r)
#define all(x) x.begin(),x.end()
#define pcnt(x) __builtin_popcountll(x)
#define fin(x) return cout<<(x)<<'\n',static_cast<void>(0)
#define yn(x) cout<<((x)?"Yes\n":"No\n")
#define uniq(x) sort(all(x)),x.erase(unique(all(x)),x.end())
template<typename T>
inline int fkey(vector<T>&z,T key){return lower_bound(z.begin(),z.end(),key)-z.begin();}
ll myceil(ll a,ll b){return (a+b-1)/b;}
template<typename T,size_t n,size_t id=0>
auto vec(const int (&d)[n],const T &init=T()){
  if constexpr (id<n)return vector(d[id],vec<T,n,id+1>(d,init));
  else return init;
}
#ifdef LOCAL
#include<debug.h>
#define SWITCH(a,b) (a)
#else
#define debug(...) static_cast<void>(0)
#define debugg(...) static_cast<void>(0)
#define SWITCH(a,b) (b)
template<typename T1,typename T2>ostream &operator<<(ostream &os,const pair<T1,T2>&p){os<<p.first<<' '<<p.second;return os;}
#endif
struct Timer{
  clock_t start;
  Timer(){
    start=clock();
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout<<fixed<<setprecision(16);
  }
  inline double now(){return (double)(clock()-start)/1000;}
  #ifdef LOCAL
  ~Timer(){
    cerr<<"time:";
    cerr<<now();
    cerr<<"ms\n";
  }
  #endif
}timer;
void SOLVE();
int main(){
  int testcase=1;
  //cin>>testcase;
  for(int i=0;i<testcase;i++){
    SOLVE();
  }
}
#include<type_traits>
#include<concepts>
template<typename T>
constexpr std::enable_if_t<std::numeric_limits<T>::digits<=32,int>msb(T n){return n==0?-1:31-__builtin_clz(n);}
template<typename T>
constexpr std::enable_if_t<(std::numeric_limits<T>::digits>32),int>msb(T n){return n==0?-1:63-__builtin_clzll(n);}

template<typename T>
constexpr std::enable_if_t<std::numeric_limits<T>::digits<=32,int>lsb(T n){return n==0?-1:__builtin_ctz(n);}
template<typename T>
constexpr std::enable_if_t<(std::numeric_limits<T>::digits>32),int>lsb(T n){return n==0?-1:__builtin_ctzll(n);}

template<typename T>
constexpr std::enable_if_t<std::is_integral_v<T>,T>floor_pow2(T n){return n==0?0:T(1)<<msb(n);}

template<typename T>
constexpr std::enable_if_t<std::is_integral_v<T>,T>ceil_pow2(T n){return n<=1?1:T(1)<<(msb(n-1)+1);}

template<std::integral T>
constexpr T safe_div(T a,T b){return a/b-(a%b&&(a^b)<0);}
template<std::integral T>
constexpr T safe_ceil(T a,T b){return a/b+(a%b&&(a^b)>0);}
template<typename M>
struct LazySegmentTree{
private:
  using S=typename M::S;
  using F=typename M::F;
  int n,z;
  int log2n;
  std::vector<S>dat;
  std::vector<F>lazy;
  inline void propagate(int i,const F&f){
    dat[i]=M::mapping(f,dat[i],1<<(log2n-msb(i)));
    lazy[i]=M::composition(f,lazy[i]);
  }
  inline void push(int i){
    if(i<z){
      propagate(i*2,lazy[i]);
      propagate(i*2+1,lazy[i]);
      lazy[i]=M::id();
    }
  }
  inline void update(int i){
    dat[i]=M::op(dat[i*2],dat[i*2+1]);
  }
  inline void path_push(int i){
    int l=lsb(i);
    for(int j=log2n;j>l;j--)push(i>>j);
  }
  inline void path_update(int i){
    int l=lsb(i);
    i>>=(l+1);
    while(i){
      update(i);
      i>>=1;
    }
  }
public:
  LazySegmentTree():n(0),z(0),log2n(0){}
  explicit LazySegmentTree(int n_):n(n_),z(ceil_pow2(n_)){
    log2n=msb(z);
    dat.resize(z*2,M::e()),lazy.resize(z*2,M::id());
  }
  explicit LazySegmentTree(const std::vector<S>&init):n(init.size()),z(ceil_pow2((int)init.size())){
    log2n=msb(z);
    dat.resize(z*2,M::e()),lazy.resize(z*2,M::id());
    for(int i=0;i<n;i++)dat[i+z]=init[i];
    for(int i=z-1;i>=1;i--)update(i);
  }
  LazySegmentTree(int n_,S init):LazySegmentTree(std::vector<S>(n_,init)){}
  void set(int i,const S&x){
    i+=z;
    for(int j=log2n;j>0;j--)push(i>>j);
    dat[i]=x;
    i>>=1;
    while(i){
      update(i);
      i>>=1;
    }
  }
  S get(int i){
    i+=z;
    for(int j=log2n;j>0;j--)push(i>>j);
    return dat[i];
  }
  void apply(int l,int r,const F&f){
    l+=z,r+=z;
    path_push(l),path_push(r);
    int l2=l,r2=r;
    while(l<r){
      if(l&1)propagate(l++,f);
      if(r&1)propagate(--r,f);
      l>>=1,r>>=1;
    }
    path_update(l2),path_update(r2);
  }
  S prod(int l,int r){
    l+=z,r+=z;
    path_push(l),path_push(r);
    S left=M::e(),right=M::e();
    while(l<r){
      if(l&1)left=M::op(left,dat[l++]);
      if(r&1)right=M::op(dat[--r],right);
      l>>=1,r>>=1;
    }
    return M::op(left,right);
  }
  inline S all_prod()const{return dat[1];}
  std::vector<S>get_all(){
    for(int i=1;i<z;i++)push(i);
    return std::vector<S>(dat.begin()+z,dat.begin()+z+n);
  }
  friend std::ostream &operator<<(std::ostream&os,const LazySegmentTree&seg){
    std::vector<F>lazy2(seg.lazy);
    for(int i=0;i<seg.n;i++)lazy2[i+seg.z]=M::id();
    for(int i=1;i<seg.z;i++){
      lazy2[i*2]=M::composition(lazy2[i],lazy2[i*2]);
      lazy2[i*2+1]=M::composition(lazy2[i],lazy2[i*2+1]);
    }
    os<<"{";
    for(int i=0;i<seg.n;i++)os<<M::mapping(lazy2[i+seg.z],seg.dat[i+seg.z],1)<<",}"[i+1==seg.n];
    if(seg.n==0)os<<"}";
    return os;
  }
};
ll h;
struct M{
  struct S{
    int idx;
    ll b,a;
  };
  using F=ll;
  static S op(S x,S y){
    if(x.idx==-1)return y;
    if(y.idx==-1)return x;
    ll xi=(h-x.b+x.a-1)/x.a;
    ll yi=(h-y.b+y.a-1)/y.a;
    return xi<=yi?x:y;
  }
  static S e(){return {-1,-1,-1};}
  static S mapping(F f,S x,ll){
    x.b+=x.a*f;
    return x;
  }
  static F composition(F f,F g){return f+g;}
  static F id(){return 0;}
};
void SOLVE(){
  int n,t;
  cin>>n>>h>>t;
  vector<ll>a(n);
  cin>>a;
  vector<typename M::S>init(n);
  rep(i,n)init[i]={i,0,a[i]};
  LazySegmentTree<M>seg(init);
  vector<int>c(n);
  while(t--){
    auto v=seg.all_prod();
    ll f=(h-v.b+v.a-1)/v.a;
    seg.apply(0,n,f);
    c[v.idx]++;
    seg.set(v.idx,{v.idx,0,a[v.idx]});
  }
  rep(i,n)cout<<c[i]<<" \n"[i+1==n];
}
0