結果
問題 | No.871 かえるのうた |
ユーザー |
![]() |
提出日時 | 2019-08-30 22:02:10 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 136 ms / 2,000 ms |
コード長 | 1,054 bytes |
コンパイル時間 | 1,749 ms |
コンパイル使用メモリ | 177,456 KB |
実行使用メモリ | 23,156 KB |
最終ジャッジ日時 | 2024-11-30 10:46:51 |
合計ジャッジ時間 | 4,537 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 49 |
ソースコード
#include <bits/stdc++.h>using namespace std;using lint = long long;template<class T = int> using V = vector<T>;template<class T = int> using VV = V< V<T> >;int main() {cin.tie(nullptr); ios::sync_with_stdio(false);int n, k; cin >> n >> k, --k;V<lint> x(n); for (auto&& e : x) cin >> e;V<lint> a(n); for (auto&& e : a) cin >> e;VV<> g(2 * n);for (int i = 0; i < n; ++i) {int l = lower_bound(begin(x), end(x), x[i] - a[i]) - begin(x);int r = upper_bound(begin(x), end(x), x[i] + a[i]) - begin(x);l += n, r += n;while (l < r) {if (l & 1) {g[n + i].push_back(l++);}if (r & 1) {g[n + i].push_back(--r);}l >>= 1, r >>= 1;}}for (int i = 1; i < n; ++i) {g[i].push_back(2 * i);g[i].push_back(2 * i + 1);}int res = 0;bitset<200000> vis;auto dfs = [&](const auto& dfs, int v) -> void {vis[v] = true;res += v >= n;for (int w : g[v]) if (!vis[w]) {dfs(dfs, w);}};dfs(dfs, n + k);cout << res << '\n';}