結果

問題 No.871 かえるのうた
ユーザー 👑 emthrmemthrm
提出日時 2019-08-30 22:48:30
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 104 ms / 2,000 ms
コード長 2,646 bytes
コンパイル時間 1,374 ms
コンパイル使用メモリ 130,312 KB
実行使用メモリ 18,696 KB
最終ジャッジ日時 2023-08-20 09:20:56
合計ジャッジ時間 4,586 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 5 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 3 ms
4,384 KB
testcase_12 AC 15 ms
5,912 KB
testcase_13 AC 5 ms
4,380 KB
testcase_14 AC 78 ms
18,236 KB
testcase_15 AC 80 ms
18,192 KB
testcase_16 AC 104 ms
17,956 KB
testcase_17 AC 66 ms
18,696 KB
testcase_18 AC 14 ms
5,952 KB
testcase_19 AC 84 ms
18,188 KB
testcase_20 AC 9 ms
4,384 KB
testcase_21 AC 32 ms
8,500 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,384 KB
testcase_25 AC 3 ms
4,376 KB
testcase_26 AC 9 ms
4,380 KB
testcase_27 AC 12 ms
5,416 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 37 ms
12,584 KB
testcase_30 AC 62 ms
14,196 KB
testcase_31 AC 3 ms
4,376 KB
testcase_32 AC 52 ms
12,884 KB
testcase_33 AC 77 ms
18,336 KB
testcase_34 AC 19 ms
7,104 KB
testcase_35 AC 45 ms
12,136 KB
testcase_36 AC 54 ms
15,268 KB
testcase_37 AC 37 ms
9,236 KB
testcase_38 AC 84 ms
16,824 KB
testcase_39 AC 76 ms
17,112 KB
testcase_40 AC 34 ms
9,880 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 33 ms
9,880 KB
testcase_43 AC 2 ms
4,380 KB
testcase_44 AC 2 ms
4,380 KB
testcase_45 AC 3 ms
4,376 KB
testcase_46 AC 2 ms
4,380 KB
testcase_47 AC 2 ms
4,380 KB
testcase_48 AC 2 ms
4,380 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