結果

問題 No.1170 Never Want to Walk
ユーザー beetbeet
提出日時 2020-08-20 13:08:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,386 ms / 2,000 ms
コード長 3,744 bytes
コンパイル時間 3,080 ms
コンパイル使用メモリ 225,292 KB
実行使用メモリ 365,700 KB
最終ジャッジ日時 2024-04-21 08:42:50
合計ジャッジ時間 18,274 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 6 ms
6,940 KB
testcase_13 AC 5 ms
6,940 KB
testcase_14 AC 6 ms
6,944 KB
testcase_15 AC 5 ms
6,940 KB
testcase_16 AC 6 ms
6,944 KB
testcase_17 AC 6 ms
6,940 KB
testcase_18 AC 6 ms
6,940 KB
testcase_19 AC 5 ms
6,940 KB
testcase_20 AC 5 ms
6,944 KB
testcase_21 AC 5 ms
6,944 KB
testcase_22 AC 6 ms
6,944 KB
testcase_23 AC 6 ms
6,940 KB
testcase_24 AC 6 ms
6,940 KB
testcase_25 AC 6 ms
6,940 KB
testcase_26 AC 6 ms
6,940 KB
testcase_27 AC 714 ms
254,560 KB
testcase_28 AC 676 ms
247,200 KB
testcase_29 AC 686 ms
258,028 KB
testcase_30 AC 703 ms
257,240 KB
testcase_31 AC 690 ms
253,388 KB
testcase_32 AC 1,161 ms
332,564 KB
testcase_33 AC 1,386 ms
342,944 KB
testcase_34 AC 1,231 ms
341,644 KB
testcase_35 AC 1,226 ms
365,700 KB
testcase_36 AC 1,159 ms
331,860 KB
testcase_37 AC 1,329 ms
333,804 KB
testcase_38 AC 1,245 ms
340,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define PROBLEM "https://yukicoder.me/problems/4387"

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

#define call_from_test

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

//BEGIN CUT HERE
template<typename T=int>
vector<T> read(size_t n){
  vector<T> ts(n);
  for(size_t i=0;i<n;i++) cin>>ts[i];
  return ts;
}
//END CUT HERE
#ifndef call_from_test
signed main(){
  return 0;
}
#endif


#ifndef call_from_test
#include <bits/stdc++.h>
using namespace std;
#endif
//BEGIN CUT HERE
template<typename T>
struct RangeToRange{
  using E = pair<int, T>;
  const int n;
  vector<vector<E>> G;
  // (0n, 2n) : top segtree (to)
  // (2n, 4n) : bottom segtree (from)
  RangeToRange(int n):n(n){
    G.resize(n*4);
    for(int i=1;i<n;i++){
      int l=(i<<1)|0;
      int r=(i<<1)|1;
      G[0*n+i].emplace_back(0*n+l,0);
      G[0*n+i].emplace_back(0*n+r,0);
      G[2*n+l].emplace_back(2*n+i,0);
      G[2*n+r].emplace_back(2*n+i,0);
    }
    for(int i=0;i<n;i++)
      G[1*n+i].emplace_back(3*n+i,0);
  }
  // [l1, r1) -> [l2, r2)
  void add_edge(int l1,int r1,int l2,int r2,T c){
    int k=G.size();
    for(l1+=n,r1+=n;l1<r1;l1>>=1,r1>>=1){
      if(l1&1) G[2*n+(l1++)].emplace_back(k,0);
      if(r1&1) G[2*n+(--r1)].emplace_back(k,0);
    }
    vector<E> es;
    for(l2+=n,r2+=n;l2<r2;l2>>=1,r2>>=1){
      if(l2&1) es.emplace_back(l2++,c);
      if(r2&1) es.emplace_back(--r2,c);
    }
    G.emplace_back(es);
  }
  int idx(int v)const{return 1*n+v;}
  size_t size()const{return G.size();}
  const vector<E>& operator[](int k)const{return G[k];}
};
//END CUT HERE
#ifndef call_from_test
//INSERT ABOVE HERE
signed main(){
  return 0;
}
#endif

#ifndef call_from_test
#include<bits/stdc++.h>
using namespace std;
#endif
//BEGIN CUT HERE
struct SCC{
  vector< vector<int> > G,R,T,C;
  vector<int> vs,used,blg;
  SCC(){}
  SCC(int n):G(n),R(n),used(n),blg(n){}

  void add_edge(int u,int v){
    G[u].emplace_back(v);
    R[v].emplace_back(u);
  }

  void dfs(int v){
    used[v]=1;
    for(int u:G[v])
      if(!used[u]) dfs(u);
    vs.emplace_back(v);
  }

  void rdfs(int v,int k){
    used[v]=1;
    blg[v]=k;
    C[k].emplace_back(v);
    for(int u:R[v])
      if(!used[u]) rdfs(u,k);
  }

  int build(){
    int n=G.size();
    for(int v=0;v<n;v++)
      if(!used[v]) dfs(v);

    fill(used.begin(),used.end(),0);
    int k=0;
    for(int i=n-1;i>=0;i--){
      if(!used[vs[i]]){
        T.emplace_back();
        C.emplace_back();
        rdfs(vs[i],k++);
      }
    }

    for(int v=0;v<n;v++)
      for(int u:G[v])
        if(blg[v]!=blg[u])
          T[blg[v]].push_back(blg[u]);

    for(int i=0;i<k;i++){
      sort(T[i].begin(),T[i].end());
      T[i].erase(unique(T[i].begin(),T[i].end()),T[i].end());
    }
    return k;
  }

  int operator[](int k) const{return blg[k];}
};
//END CUT HERE
#ifndef call_from_test
signed main(){
  return 0;
}
#endif

#undef call_from_test

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  const char newl = '\n';

  int n,a,b;
  cin>>n>>a>>b;

  auto xs=read(n);

  RangeToRange<int> G(n);
  for(int i=0;i<n;i++){
    // [x - B, x - A]
    {
      int l=lower_bound(xs.begin(),xs.end(),xs[i]-b)-xs.begin();
      int r=upper_bound(xs.begin(),xs.end(),xs[i]-a)-xs.begin();
      G.add_edge(i,i+1,l,r,0);
    }
    // [x + A, x + B]
    {
      int l=lower_bound(xs.begin(),xs.end(),xs[i]+a)-xs.begin();
      int r=upper_bound(xs.begin(),xs.end(),xs[i]+b)-xs.begin();
      G.add_edge(i,i+1,l,r,0);
    }
  }

  SCC scc(G.size());
  for(int v=0;v<(int)G.size();v++)
    for(auto [u,c]:G[v]) scc.add_edge(v,u);
  scc.build();

  map<int, int> cnt;
  for(int i=0;i<n;i++) cnt[scc[G.idx(i)]]++;
  for(int i=0;i<n;i++) cout<<cnt[scc[G.idx(i)]]<<newl;
  return 0;
}
0