Submission #1123307

#TimeUsernameProblemLanguageResultExecution timeMemory
1123307Neco_arcAdvertisement 2 (JOI23_ho_t2)C++20
33 / 100
586 ms22020 KiB
#include <bits/stdc++.h> #define ll long long #define name "Advertisement" #define all(x) x.begin(), x.end() #define _left id * 2, l, mid #define _right id * 2 + 1, mid + 1, r #define fi(i, a, b) for(int i = a; i <= b; ++i) #define fid(i, a, b) for(int i = a; i >= b; --i) #define maxn (int) (5e5 + 7) using namespace std; int n; pair<int, int> a[maxn]; vector<int> Comp; struct IT { int st[4 * maxn]; IT() { memset(st, -60, sizeof st); } void update(int x, int val, int id = 1, int l = 1, int r = n) { if(l > x || r < x) return; if(l == r) return st[id] = val, void(); int mid = (l + r) >> 1; update(x, val, _left), update(x, val, _right); st[id] = max(st[id * 2], st[id * 2 + 1]); } int get(int u, int v, int id = 1, int l = 1, int r = n) { if(l > v || r < u) return -2e9; if(u <= l && r <= v) return st[id]; int mid = (l + r) >> 1; return max(get(u, v, _left), get(u, v, _right)); } } StMax, StMin; void solve() { cin >> n; fi(i, 1, n) cin >> a[i].first >> a[i].second; fi(i, 1, n) Comp.push_back(a[i].first); sort(all(Comp)); Comp.resize(unique(all(Comp)) - Comp.begin()); sort(a + 1, a + 1 + n, [](pair<int, int> x, pair<int, int> y) { return x.second > y.second; }); int ans = 0; fi(i, 1, n) { int x = a[i].first, e = a[i].second; int it = upper_bound(all(Comp), x) - Comp.begin(); bool ok = 1; if( StMax.get(1, it) >= x + e) ok = 0; if(-StMin.get(it, n) <= x - e) ok = 0; ans += ok; StMax.update(it, x + e); StMin.update(it, -(x - e)); } cout << ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0); if(fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); } solve(); }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:80:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   80 |         freopen(name".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:81:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |         freopen(name".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...