Submission #1164999

#TimeUsernameProblemLanguageResultExecution timeMemory
1164999pinbuAdvertisement 2 (JOI23_ho_t2)C++20
100 / 100
157 ms17156 KiB
#include <bits/stdc++.h> using namespace std; const int N = 500005; const long long oo = 1e18; int n; array<int, 3> a[N], b[N]; vector<int> idas, idbs; void solve(void) { cin >> n; for (int i = 1, x, e; i <= n; i++) { cin >> x >> e; a[i] = {x, x + e, i}; b[i] = {x, x - e, i}; } sort(a + 1, a + 1 + n, [&] (const array<int, 3> &X, const array<int, 3> &Y) { return X[0] < Y[0] || (X[0] == Y[0] && (X[1] > Y[1] || (X[1] == Y[1] && X[2] < Y[2]))); }); sort(b + 1, b + 1 + n, [&] (const array<int, 3> &X, const array<int, 3> &Y) { return X[0] < Y[0] || (X[0] == Y[0] && (X[1] > Y[1] || (X[1] == Y[1] && X[2] < Y[2]))); }); for (int i = n; i; i--) { if (idas.empty() || a[i][1] ^ a[idas.back()][1] || a[i][0] ^ a[idas.back()][0]) { while (!idas.empty() && (a[i][1] >= a[idas.back()][1] || (a[i][1] == a[idas.back()][1] && a[i][0] ^ a[idas.back()][0]))) idas.pop_back(); idas.emplace_back(i); } } reverse(begin(idas), end(idas)); for (int i = 1; i <= n; i++) { while (!idbs.empty() && b[i][1] <= b[idbs.back()][1]) idbs.pop_back(); idbs.emplace_back(i); } int ans = 0; for (int i = 0, j = 0; i < (int)idas.size() && j < (int)idbs.size();) { int i1 = idas[i], i2 = idbs[j]; if (a[i1][0] < b[i2][0]) i++; else if (a[i1][0] > b[i2][0]) j++; else { ans += (a[i1][2] == b[i2][2]); i++; j++; } } cout << ans; } signed main(void) { ios::sync_with_stdio(false); cin.tie(nullptr); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...