제출 #1290350

#제출 시각아이디문제언어결과실행 시간메모리
1290350yonatanlLightning Rod (NOI18_lightningrod)C++20
100 / 100
431 ms234360 KiB
#include <iostream> #include <vector> #include <algorithm> #include <set> #include <string> #define rep(i, s, e) for (ll i = s; i < e; i++) #define upmax(a, b) a = max(a, b) #define upmin(a, b) a = min(a, b) using namespace std; using ll = int; using vll = vector<ll>; using vvll = vector<vll>; using pll = pair<ll, ll>; using vpll = vector<pll>; inline int readInt() { int x = 0; char ch = getchar_unlocked(); bool s = 1; while (ch < '0' || ch>'9') { if (ch == '-')s = 0; ch = getchar_unlocked(); } while (ch >= '0' && ch <= '9') { x = (x << 3) + (x << 1) + ch - '0'; ch = getchar_unlocked(); } return s ? x : -x; } void solve() { ll n; n = readInt(); vpll p(n); rep(i, 0, n) { p[i].first = readInt(); p[i].second = readInt(); } vpll arr(n); rep(i, 0, n) { arr[i].first = p[i].first - p[i].second; arr[i].second = p[i].first + p[i].second; } vpll pref(n); pref[n - 1].first = arr[n - 1].first; pref[0].second = arr[0].second; rep(i, 1, n) pref[i].second = max(pref[i - 1].second, arr[i].second); for (ll i = n - 2; i >= 0; i--) pref[i].first = min(pref[i + 1].first, arr[i].first); ll ans = n; rep(i, 0, n) { if ((i < n - 1 && pref[i + 1].first <= arr[i].first) || (i > 0 && pref[i - 1].second >= arr[i].second)) { ans--; } } cout << ans << '\n'; /* vector<bool> ans(n, true); ll mn = arr[n - 1]; for (ll i = n - 2; i >= 0; i--) { if (arr[i] >= mn) { ans[i] = false; } else mn = arr[i]; } ll mx = arr2[0]; rep(i, 1, n) { if (arr2[i] <= mx) { ans[i] = false; } else mx = arr2[i]; } ll res = 0; rep(i, 0, n) if (ans[i]) res++; cout << res << '\n';*/ } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...