Submission #1281832

#TimeUsernameProblemLanguageResultExecution timeMemory
1281832muhammad-ahmadAdvertisement 2 (JOI23_ho_t2)C++20
59 / 100
2095 ms12788 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define endl '\n' void solve(){ int n; cin >> n; int X[n + 1] = {}, E[n + 1] = {}; bool Sub1 = 1, Sub2 = (n <= 16); map<int, int> MA; for (int i = 1; i <= n; i++){ cin >> X[i] >> E[i]; if (E[MA[X[i]]] < E[i]) MA[X[i]] = i; if (i > 1 && E[i] != E[i - 1]) Sub1 = 0; } // if (Sub1){ // map<int, int> C; // int ans = 0; // for (int i = 1; i <= n; i++){ // C[X[i]]++; // if (C[X[i]] == 1) ans++; // } // cout << ans << endl; // return; // } // else if (Sub2){ // int ans = 16; // for (int i = 1; i <= (1LL << n); i++){ // vector<int> x; // for (int j = 0; j < n; j++){ // if ((i >> j) & 1) x.push_back(j + 1); // } // bool vis[n + 1] = {}; // for (auto j : x){ // for (int k = 1; k <= n; k++){ // if (abs(X[k] - X[j]) <= E[j] - E[k]) vis[k] = 1; // } // } // // int pos = 0; // // for (int j = 1; j <= n; j++) pos += vis[j]; // if (pos == n) ans = min(ans, (int)x.size()); // } // cout << ans << endl; // return; // } map<int, vector<int>> C; int ans = 0; vector<int> a; for (int i = 1; i <= n; i++){ C[E[i]].push_back(i); if (C[E[i]].size() == 1) a.push_back(E[i]); } int vis[n + 1] = {}; sort(rbegin(a), rend(a)); set<int> idx1, idx2; for (auto v : a){ for (auto i : C[v]){ auto it1 = lower_bound(idx1.begin(), idx1.end(), X[i]); auto it2 = lower_bound(idx2.begin(), idx2.end(), -X[i]); if (it1 != idx1.end()){ int x = *it1; int j = MA[x]; // cout << i << ' ' << j << endl; if (abs(X[j] - X[i]) <= E[j] - E[i]) vis[i] = 2; } if (it2 != idx2.end()){ int x = *it2; x *= -1; int j = MA[x]; if (abs(X[j] - X[i]) <= E[j] - E[i]) vis[i] = 2; // cout << i << ' ' << j << endl; } if (vis[i] == 0){ // cout << i << endl; idx1.insert(X[i]); idx2.insert(-X[i]); vis[i] = 1; ans++; } // cout << '-' << endl; } } // for (int i = 1; i <= n; i++) cout << vis[i] << ' '; // cout << endl; cout << ans << endl; } signed main(){ int tc = 1; // cin >> tc; while (tc--){ 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...