結果

問題 No.1014 competitive fighting
ユーザー 👑 emthrmemthrm
提出日時 2020-03-22 23:52:56
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 66 ms / 2,000 ms
コード長 5,386 bytes
コンパイル時間 5,135 ms
コンパイル使用メモリ 217,012 KB
実行使用メモリ 11,152 KB
最終ジャッジ日時 2023-08-08 20:43:43
合計ジャッジ時間 13,928 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 65 ms
8,576 KB
testcase_06 AC 65 ms
8,636 KB
testcase_07 AC 65 ms
8,596 KB
testcase_08 AC 65 ms
8,572 KB
testcase_09 AC 66 ms
8,720 KB
testcase_10 AC 51 ms
11,152 KB
testcase_11 AC 53 ms
8,280 KB
testcase_12 AC 65 ms
8,460 KB
testcase_13 AC 31 ms
5,576 KB
testcase_14 AC 28 ms
5,596 KB
testcase_15 AC 34 ms
6,112 KB
testcase_16 AC 3 ms
4,384 KB
testcase_17 AC 12 ms
4,380 KB
testcase_18 AC 54 ms
7,732 KB
testcase_19 AC 63 ms
8,304 KB
testcase_20 AC 23 ms
5,096 KB
testcase_21 AC 49 ms
7,516 KB
testcase_22 AC 39 ms
6,132 KB
testcase_23 AC 16 ms
4,384 KB
testcase_24 AC 16 ms
4,384 KB
testcase_25 AC 5 ms
4,384 KB
testcase_26 AC 48 ms
7,520 KB
testcase_27 AC 12 ms
4,384 KB
testcase_28 AC 14 ms
4,396 KB
testcase_29 AC 2 ms
4,384 KB
testcase_30 AC 64 ms
8,204 KB
testcase_31 AC 50 ms
7,672 KB
testcase_32 AC 3 ms
4,380 KB
testcase_33 AC 5 ms
4,380 KB
testcase_34 AC 45 ms
7,416 KB
testcase_35 AC 58 ms
8,036 KB
testcase_36 AC 41 ms
7,400 KB
testcase_37 AC 3 ms
4,380 KB
testcase_38 AC 37 ms
6,020 KB
testcase_39 AC 18 ms
4,580 KB
testcase_40 AC 35 ms
5,864 KB
testcase_41 AC 26 ms
5,500 KB
testcase_42 AC 57 ms
7,944 KB
testcase_43 AC 4 ms
4,384 KB
testcase_44 AC 51 ms
7,676 KB
testcase_45 AC 31 ms
5,892 KB
testcase_46 AC 6 ms
4,380 KB
testcase_47 AC 17 ms
4,448 KB
testcase_48 AC 43 ms
7,152 KB
testcase_49 AC 3 ms
4,380 KB
testcase_50 AC 54 ms
7,800 KB
testcase_51 AC 32 ms
5,576 KB
testcase_52 AC 3 ms
4,384 KB
testcase_53 AC 66 ms
8,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

template <typename Monoid>
struct RMQ {
  RMQ(int sz, const Monoid UNITY) : UNITY(UNITY) {
    init(sz);
    dat.assign((n << 1) - 1, UNITY);
  }

  RMQ(const vector<Monoid> &a, const Monoid UNITY) : UNITY(UNITY) {
    int a_sz = a.size();
    init(a_sz);
    dat.resize((n << 1) - 1);
    REP(i, a_sz) dat[n - 1 + i] = a[i];
    for (int i = n - 2; i >= 0; --i) dat[i] = max(dat[(i << 1) + 1], dat[(i << 1) + 2]);
  }

  void update(int node, Monoid val) {
    node += n - 1;
    dat[node] = val;
    while (node > 0) {
      node = (node - 1) >> 1;
      dat[node] = max(dat[(node << 1) + 1], dat[(node << 1) + 2]);
    }
  }

  Monoid query(int a, int b) { return query(a, b, 0, 0, n); }

  int find(int a, int b, Monoid val) { return find(a, b, val, 0, 0, n); }

  Monoid operator[](const int idx) const { return dat[idx + n - 1]; }

private:
  int n = 1;
  const Monoid UNITY;
  vector<Monoid> dat;

  void init(int sz) { while (n < sz) n <<= 1; }

  Monoid query(int a, int b, int node, int left, int right) {
    if (right <= a || b <= left) return UNITY;
    if (a <= left && right <= b) return dat[node];
    return max(query(a, b, (node << 1) + 1, left, (left + right) >> 1), query(a, b, (node << 1) + 2, (left + right) >> 1, right));
  }

  int find(int a, int b, Monoid val, int node, int left, int right) {
    if (dat[node] < val || right <= a || b <= left) return -1;
    if (right - left == 1) return node - (n - 1);
    int res_l = find(a, b, val, (node << 1) + 1, left, (left + right) >> 1);
    if (res_l != -1) return res_l;
    return find(a, b, val, (node << 1) + 2, (left + right) >> 1, right);
  }
};

template <typename Abelian>
struct BIT0based {
  BIT0based(int n, const Abelian UNITY = 0) : n(n), UNITY(UNITY), dat(n, UNITY) {}

  void add(int idx, Abelian val) {
    while (idx < n) {
      dat[idx] += val;
      idx |= idx + 1;
    }
  }

  Abelian sum(int idx) {
    Abelian res = UNITY;
    --idx;
    while (idx >= 0) {
      res += dat[idx];
      idx = (idx & (idx + 1)) - 1;
    }
    return res;
  }

  Abelian sum(int left, int right) {
    if (right <= left) return UNITY;
    return sum(right) - sum(left);
  }

  Abelian operator[](const int idx) { return sum(idx, idx + 1); }

  int lower_bound(Abelian val) {
    if (val <= UNITY) return 0;
    int res = 0, exponent = 1;
    while (exponent <= n) exponent <<= 1;
    for (int mask = exponent >> 1; mask > 0; mask >>= 1) {
      if (res + mask - 1 < n && dat[res + mask - 1] < val) {
        val -= dat[res + mask - 1];
        res += mask;
      }
    }
    return res;
  }

private:
  int n;
  const Abelian UNITY;
  vector<Abelian> dat;
};

int main() {
  int n; cin >> n;
  struct Skill {
    int a, x, b, query;
    Skill(int a, int b, int c, int query) : a(a), b(b), query(query) { x = b - c; }
    bool operator<(const Skill &r) {
      return a != r.a ? a < r.a : x != r.x ? x < r.x : b < r.b;
    };
  };
  vector<Skill> skills;
  REP(i, n) {
    int a, b, c; cin >> a >> b >> c;
    skills.emplace_back(a, b, c, i);
  }
  sort(ALL(skills));
  vector<int> gen(n);
  REP(i, n) gen[i] = skills[i].a;
  vector<ll> ans(n, LINF);
  RMQ<ll> rmq(n, -LINF);
  BIT0based<int> bit(n);
  using P = pair<ll, int>;
  priority_queue<P, vector<P>, greater<P> > que;
  int border = -1;
  REP(i, n) {
    while (!que.empty() && que.top().first < skills[i].a) {
      int idx = que.top().second; que.pop();
      bit.add(idx, -1);
      int r = i - 1;
      if (border <= idx && bit.sum(r) == 0) {
        ans[skills[idx].query] = max(rmq.query(0, r), 0LL) + skills[idx].b;
        rmq.update(idx, ans[skills[idx].query]);
      } else {
        bit.add(idx, 1);
      }
      chmax(border, r);
    }
    if (skills[i].x < skills[i].a) {
      int r = upper_bound(ALL(gen), skills[i].x) - gen.begin();
      if (border <= i && bit.sum(r) == 0) {
        ans[skills[i].query] = max(rmq.query(0, r), 0LL) + skills[i].b;
        rmq.update(i, ans[skills[i].query]);
      }
      chmax(border, r);
    } else {
      que.emplace(skills[i].x, i);
      bit.add(i, 1);
    }
  }
  while (!que.empty()) {
    int idx = que.top().second; que.pop();
    bit.add(idx, -1);
    int r = upper_bound(ALL(gen), skills[idx].x) - gen.begin();
    if (border <= idx && bit.sum(r) == 0) {
      ans[skills[idx].query] = max(rmq.query(0, r), 0LL) + skills[idx].b;
      rmq.update(idx, ans[skills[idx].query]);
    }
    chmax(border, r);
  }
  REP(i, n) {
    if (ans[i] == LINF) {
      cout << "BAN\n";
    } else {
      cout << ans[i] << '\n';
    }
  }
  return 0;
}
0