| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1360616 | rukashii | Advertisement 2 (JOI23_ho_t2) | C++20 | 479 ms | 88016 KiB |
#include <bits/stdc++.h>
using namespace std;
#define file \
if (fopen("input.txt", "r")) \
{ \
freopen("input.txt", "r", stdin); \
freopen("output.txt", "w", stdout); \
}
#define int long long
#define x first
#define e second
void setIn(string s) { freopen(s.c_str(), "r", stdin); }
void setOut(string s) { freopen(s.c_str(), "w", stdout); }
void setIO(string s = "")
{
if (s.size())
setIn(s + ".inp"), setOut(s + ".out");
}
const int maxn = 5e5 + 2;
vector<int> adj[maxn];
bool vis[maxn];
void dfs(int u)
{
vis[u] = 1;
for (int v : adj[u])
{
if (vis[v])
continue;
dfs(v);
}
}
void solve()
{
int n;
cin >> n;
vector<pair<int, int>> a(n + 2);
vector<int> deg(n + 2, 0);
for (int i = 1; i <= n; i++)
cin >> a[i].x >> a[i].e;
sort(a.begin() + 1, a.begin() + 1 + n);
// for (int i = 1; i <= n; i++)
// cout << a[i].x << ' ' << a[i].e << '\n';
// cout << '\n';
set<pair<int, int>> nL, nR;
for (int i = 1; i <= n; i++)
nR.insert({a[i].x + a[i].e, i});
for (int i = 1; i <= n; i++)
{
nR.erase(nR.find({a[i].x + a[i].e, i}));
auto it = nL.upper_bound({a[i].e - a[i].x, INT_MAX});
if (it != nL.begin())
{
auto [val, pos] = *(--it);
deg[pos]++;
adj[i].push_back(pos);
}
auto it2 = nR.upper_bound({a[i].e + a[i].x, INT_MAX});
if (it2 != nR.begin())
{
auto [val, pos] = *(--it2);
deg[pos]++;
adj[i].push_back(pos);
// cout << "2 " << i << ' ' << pos << '\n';
}
nL.insert({a[i].e - a[i].x, i});
}
vector<pair<int, int>> cur;
for (int i = 1; i <= n; i++)
cur.push_back({deg[i], i});
sort(cur.begin(), cur.end());
int ans = 0;
for (auto [d, u] : cur)
if (!vis[u])
ans++, dfs(u);
cout << ans << '\n';
}
signed main()
{
// setIO();
file;
ios::sync_with_stdio(0);
cin.tie(0);
solve();
}Compilation message (stderr)
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
