結果

問題 No.871 かえるのうた
ユーザー 👑 emthrmemthrm
提出日時 2019-08-30 22:48:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 2,646 bytes
コンパイル時間 1,821 ms
コンパイル使用メモリ 131,060 KB
実行使用メモリ 18,932 KB
最終ジャッジ日時 2024-05-07 16:25:05
合計ジャッジ時間 3,988 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 4 ms
6,944 KB
testcase_09 AC 4 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 14 ms
6,940 KB
testcase_13 AC 4 ms
6,940 KB
testcase_14 AC 70 ms
18,836 KB
testcase_15 AC 74 ms
18,932 KB
testcase_16 AC 96 ms
18,904 KB
testcase_17 AC 60 ms
17,980 KB
testcase_18 AC 13 ms
6,940 KB
testcase_19 AC 72 ms
18,648 KB
testcase_20 AC 9 ms
6,940 KB
testcase_21 AC 29 ms
8,740 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 1 ms
6,944 KB
testcase_24 AC 1 ms
6,944 KB
testcase_25 AC 3 ms
6,944 KB
testcase_26 AC 9 ms
6,940 KB
testcase_27 AC 11 ms
6,944 KB
testcase_28 AC 2 ms
6,944 KB
testcase_29 AC 34 ms
12,688 KB
testcase_30 AC 55 ms
14,176 KB
testcase_31 AC 3 ms
6,940 KB
testcase_32 AC 47 ms
13,112 KB
testcase_33 AC 71 ms
18,228 KB
testcase_34 AC 18 ms
7,312 KB
testcase_35 AC 39 ms
12,424 KB
testcase_36 AC 47 ms
15,464 KB
testcase_37 AC 32 ms
9,392 KB
testcase_38 AC 75 ms
18,076 KB
testcase_39 AC 67 ms
17,112 KB
testcase_40 AC 30 ms
10,128 KB
testcase_41 AC 2 ms
6,940 KB
testcase_42 AC 30 ms
10,124 KB
testcase_43 AC 2 ms
6,940 KB
testcase_44 AC 2 ms
6,940 KB
testcase_45 AC 2 ms
6,944 KB
testcase_46 AC 2 ms
6,944 KB
testcase_47 AC 2 ms
6,940 KB
testcase_48 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
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()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n, k; cin >> n >> k; --k;
  vector<long long> x(n), a(n), comp;
  REP(i, n) cin >> x[i];
  REP(i, n) cin >> a[i];
  REP(i, n) {
    comp.emplace_back(x[i] - a[i]);
    comp.emplace_back(x[i]);
    comp.emplace_back(x[i] + a[i]);
  }
  sort(ALL(comp));
  comp.erase(unique(ALL(comp)), comp.end());
  int sz = comp.size();
  vector<int> l(n), r(n);
  vector<vector<int> > pos(sz);
  REP(i, n) {
    l[i] = lower_bound(ALL(comp), x[i] - a[i]) - comp.begin();
    r[i] = lower_bound(ALL(comp), x[i] + a[i]) - comp.begin();
    x[i] = lower_bound(ALL(comp), x[i]) - comp.begin();
    pos[x[i]].emplace_back(i);
  }
  int left = l[k], old_l = l[k], right = r[k], old_r = r[k];
  FOR(i, old_l, old_r + 1) {
    for (int e : pos[i]) {
      left = min(left, l[e]);
      right = max(right, r[e]);
    }
  }
  bool update = true;
  while (update) {
    update = false;
    int tmp_l = left, tmp_r = right;
    FOR(i, tmp_l, old_l) if (!pos[i].empty()) {
      for (int e : pos[i]) {
        if (l[e] < left) {
          left = l[e];
          update = true;
        }
        if (right < r[e]) {
          right = r[e];
          update = true;
        }
      }
    }
    FOR(i, old_r + 1, tmp_r + 1) if (!pos[i].empty()) {
      for (int e : pos[i]) {
        if (l[e] < left) {
          left = l[e];
          update = true;
        }
        if (right < r[e]) {
          right = r[e];
          update = true;
        }
      }
    }
    old_l = tmp_l;
    old_r = tmp_r;
  }
  // cout << left << ' ' << right << '\n';
  int ans = 0;
  REP(i, n) {
    if (left <= x[i] && x[i] <= right) ++ans;
  }
  cout << ans << '\n';
  return 0;
}
0