Submission #1124922

#TimeUsernameProblemLanguageResultExecution timeMemory
1124922panAdvertisement 2 (JOI23_ho_t2)C++20
100 / 100
745 ms102792 KiB
#include <bits/stdc++.h> //#include "includeall.h" //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> #define endl '\n' #define f first #define s second #define pb push_back #define mp make_pair #define lb lower_bound #define ub upper_bound #define input(x) scanf("%lld", &x); #define input2(x, y) scanf("%lld%lld", &x, &y); #define input3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z); #define input4(x, y, z, a) scanf("%lld%lld%lld%lld", &x, &y, &z, &a); #define print(x, y) printf("%lld%c", x, y); #define show(x) cerr << #x << " is " << x << endl; #define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl; #define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl; #define all(x) x.begin(), x.end() #define discretize(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end()); #define FOR(i, x, n) for (ll i =x; i<=n; ++i) #define RFOR(i, x, n) for (ll i =x; i>=n; --i) using namespace std; //using namespace __gnu_pbds; //#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> //#define ordered_multiset tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> typedef long long ll; //typedef __int128 ull; typedef long double ld; typedef pair<ld, ll> pd; typedef pair<string, ll> psl; typedef pair<ll, ll> pi; typedef pair<pi, ll> pii; typedef pair<pi, pi> piii; ll const INF = 1e13; struct node { int s, e, m; pi minn, maxx; node * l, * r; node(int S, int E) { s = S, e = E, m = (s + e) / 2; minn = maxx = mp(0, s); if (s != e) { l = new node(s, m); r = new node(m + 1, e); } } void update(int X, ll m1,ll m2) { if (s == e) minn = mp(m1, s), maxx = mp(m2, s); else { if (X <= m) l -> update(X, m1, m2); else r -> update(X, m1, m2); minn = min(l->minn, r->minn); maxx = max(l->maxx, r-> maxx); } } pi querymin(int S, int E) { if (S > E) return mp(INF, -1); if (s == S && e == E) return minn; else if (E <= m) return l -> querymin(S, E); else if (S >= m + 1) return r -> querymin(S, E); else return min(l -> querymin(S, m), r -> querymin(m + 1, E)); } pi querymax(int S, int E) { if (S > E) return mp(-INF, -1); if (s == S && e == E) return maxx; else if (E <= m) return l -> querymax(S, E); else if (S >= m + 1) return r -> querymax(S, E); else return max(l -> querymax(S, m), r -> querymax(m + 1, E)); } }* root; ll x[500005], e[500005]; bool die[500005]; int main() { ll n; cin >> n; root = new node(1, n); vector<pi> v, v2(n); for (ll i=0; i<n; ++i) { input2(v2[i].f, v2[i].s); } sort(all(v2)); for (ll i=1; i<=n; ++i) { x[i] = v2[i-1].f, e[i] = v2[i-1].s; die[i] = 0; root->update(i, x[i] + e[i], x[i] - e[i]); v.pb(mp(e[i], i)); //show2(x[i], e[i]); } sort(all(v), greater<pi>()); ll ans = 0; for (ll i=0; i<n; ++i) { ll idx = v[i].s; if (die[idx]) continue; //show(idx); die[idx] = 1; ans++; root->update(idx, INF, -INF); while (1) { pi cur = root->querymax(1, idx-1); if (cur.f < x[idx] - e[idx]) break; die[cur.s] = 1; root->update(cur.s, INF, -INF); } while (1) { pi cur = root->querymin(idx+1, n); if (cur.f > x[idx] + e[idx]) break; die[cur.s] = 1; root->update(cur.s, INF, -INF); } } cout << ans << endl; return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:13:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 | #define input2(x, y) scanf("%lld%lld", &x, &y);
      |                      ~~~~~^~~~~~~~~~~~~~~~~~~~
Main.cpp:87:17: note: in expansion of macro 'input2'
   87 |                 input2(v2[i].f, v2[i].s);
      |                 ^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...