結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,812 KB
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 AC 3 ms
6,944 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(300000);
  int ret = 0;
  for (auto &pr: p) {
    int x, r;
    tie(x, r) = pr;
    tree.add(x - r + 150000, 1);
    ret = max(ret, tree.sum(x + r + 150000 - 1));
  }
  
  cout << ret << endl;

  return 0;
}
0