結果

問題 No.1137 Circles
ユーザー kk
提出日時 2020-08-08 21:54:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,038 bytes
コンパイル時間 2,148 ms
コンパイル使用メモリ 205,256 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-10 06:23:28
合計ジャッジ時間 3,457 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,816 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 3 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)

template <typename T>
class BIT {
  vector<T> bit;
public:
  BIT() {}
  // manage data in [1, n]
  BIT(int n) : bit(n + 1) {}
  
  void init() {
    fill(bit.begin(), bit.end(), 0);
  }
  
  // return sum in [1, i]
  T sum(int i){
    T s = 0;
    while(i > 0){
      s += bit[i];
      i -= i & -i;
    }
    return s;
  }
  
  // return sum in [l, r]
  T sum(int l, int r) {
    return sum(r) - sum(l-1);
  }
  
  void add(int i, T x){
    while(i < (int)bit.size()){
      bit[i] += x;
      i += i & -i;
    }
  }
};

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  cin >> n;
  vector<pair<int, int> > p(n);
  REP (i, n)
    cin >> p[i].first >> p[i].second;

  sort(p.rbegin(), p.rend());

  BIT<int> tree(500000);
  int ret = 0;
  for (auto &pr: p) {
    int x, r;
    tie(x, r) = pr;
    tree.add(x - r + 222222, 1);
    ret = max(ret, tree.sum(x + r + 222222 - 1));
  }
  
  cout << ret << endl;

  return 0;
}
0