結果
問題 | No.871 かえるのうた |
ユーザー | 👑 emthrm |
提出日時 | 2019-08-30 22:48:30 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 104 ms / 2,000 ms |
コード長 | 2,646 bytes |
コンパイル時間 | 1,448 ms |
コンパイル使用メモリ | 126,928 KB |
最終ジャッジ日時 | 2025-01-07 16:00:24 |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 49 |
ソースコード
#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; }