結果

問題 No.1170 Never Want to Walk
ユーザー rnanornano
提出日時 2023-01-28 01:27:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 375 ms / 2,000 ms
コード長 2,016 bytes
コンパイル時間 1,669 ms
コンパイル使用メモリ 171,056 KB
実行使用メモリ 6,020 KB
最終ジャッジ日時 2023-09-10 18:35:21
合計ジャッジ時間 9,435 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 4 ms
4,376 KB
testcase_13 AC 4 ms
4,376 KB
testcase_14 AC 4 ms
4,380 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 4 ms
4,376 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 AC 4 ms
4,376 KB
testcase_19 AC 4 ms
4,380 KB
testcase_20 AC 4 ms
4,380 KB
testcase_21 AC 4 ms
4,376 KB
testcase_22 AC 4 ms
4,376 KB
testcase_23 AC 4 ms
4,380 KB
testcase_24 AC 4 ms
4,376 KB
testcase_25 AC 4 ms
4,380 KB
testcase_26 AC 4 ms
4,376 KB
testcase_27 AC 347 ms
5,828 KB
testcase_28 AC 356 ms
5,920 KB
testcase_29 AC 354 ms
5,952 KB
testcase_30 AC 355 ms
5,868 KB
testcase_31 AC 345 ms
5,920 KB
testcase_32 AC 343 ms
5,832 KB
testcase_33 AC 343 ms
5,876 KB
testcase_34 AC 360 ms
6,020 KB
testcase_35 AC 356 ms
5,916 KB
testcase_36 AC 348 ms
5,968 KB
testcase_37 AC 348 ms
5,840 KB
testcase_38 AC 375 ms
5,876 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i,n) for (int i = (int)(n-1); i >= 0; --i)
#define Rep(i,a,b) for (int i = a; i < b; ++i)
#define rRep(i,a,b) for (int i = a; i > b; --i)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define Bit(x,i) (((x)>>(i))&1)
using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const double PI = acos(-1);
const int INF = 1e9+2;
const ll LINF = 3e18;

struct UnionFind {
  vector<int> par;
  UnionFind() { }
  UnionFind(int n) : par(n, -1) { }
  void init(int n) { par.assign(n, -1); }
  int root(int x) {
    if (par[x] < 0) return x;
    else return par[x] = root(par[x]);
  }
  bool issame(int x, int y) {
    return root(x) == root(y);
  }
  bool merge(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (par[x] > par[y]) swap(x, y);
    par[x] += par[y];
    par[y] = x;
    return true;
  }
  int size(int x) {
    return -par[root(x)];
  }
};

vll X;
UnionFind uf(200100);

int main() {
  ll N, A, B; cin >> N >> A >> B;
  rep(i, N) {
    ll x; cin >> x;
    X.push_back(x);
  }
  rep(i, N) {
    int ldx = lower_bound(all(X), X[i]+A) - X.begin();
    int rdx = lower_bound(all(X), X[i]+B+1) - X.begin() - 1;
    if(ldx > rdx) continue;
    uf.merge(i, ldx);
    uf.merge(i, rdx);
    while(ldx < rdx) {
      if(uf.issame(ldx, ldx+1)) break;
      uf.merge(ldx, ldx+1);
      ldx++;
    }
    while(ldx < rdx) {
      if(uf.issame(rdx-1, rdx)) break;
      uf.merge(rdx-1, rdx);
      rdx--;
    }
  }
  rep(i, N) {
    cout << uf.size(i) << endl;
  }
}
0