Submission #741578

#TimeUsernameProblemLanguageResultExecution timeMemory
741578maomao90Advertisement 2 (JOI23_ho_t2)C++17
100 / 100
338 ms32972 KiB
// Hallelujah, praise the one who set me free // Hallelujah, death has lost its grip on me // You have broken every chain, There's salvation in your name // Jesus Christ, my living hope #include <bits/stdc++.h> using namespace std; #define REP(i, s, e) for (int i = (s); i < (e); i++) #define RREP(i, s, e) for (int i = (s); i >= (e); i--) template <class T> inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;} template <class T> inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;} typedef long long ll; typedef long double ld; #define FI first #define SE second typedef pair<int, int> ii; typedef pair<ll, ll> pll; typedef tuple<int, int, int> iii; #define ALL(_a) _a.begin(), _a.end() #define SZ(_a) (int) _a.size() #define pb push_back typedef vector<int> vi; typedef vector<ll> vll; typedef vector<ii> vii; typedef vector<iii> viii; #ifndef DEBUG #define cerr if (0) cerr #endif const int INF = 2000000005; const ll LINF = 1000000000000000005ll; const int MAXN = 500005; int n; ii xe[MAXN]; int inv[MAXN]; vii ord; int ans; #define MLR int mid = lo + hi >> 1, lc = u << 1, rc = u << 1 ^ 1 int sub[MAXN * 4], add[MAXN * 4]; void upd(int p, int s, int a, int u = 1, int lo = 1, int hi = n) { if (lo == hi) { mxto(sub[u], s); mxto(add[u], a); return; } MLR; if (p <= mid) { upd(p, s, a, lc, lo, mid); } else { upd(p, s, a, rc, mid + 1, hi); } sub[u] = max(sub[lc], sub[rc]); add[u] = max(add[lc], add[rc]); cerr << u << ' ' << lo << ' ' << hi << ": " << sub[u] << '\n'; } int qsub(int s, int e, int u = 1, int lo = 1, int hi = n) { if (lo >= s && hi <= e) { return sub[u]; } MLR; int mx = -INF; if (s <= mid) { mxto(mx, qsub(s, e, lc, lo, mid)); } if (e > mid) { mxto(mx, qsub(s, e, rc, mid + 1, hi)); } return mx; } int qadd(int s, int e, int u = 1, int lo = 1, int hi = n) { if (lo >= s && hi <= e) { return add[u]; } MLR; int mx = -INF; if (s <= mid) { mxto(mx, qadd(s, e, lc, lo, mid)); } if (e > mid) { mxto(mx, qadd(s, e, rc, mid + 1, hi)); } return mx; } int main() { #ifndef DEBUG ios::sync_with_stdio(0), cin.tie(0); #endif cin >> n; REP (i, 0, n) { cin >> xe[i].FI >> xe[i].SE; } sort(xe, xe + n); REP (i, 0, n) { ord.pb({xe[i].SE, i}); } int prv = -1, ptr = 0; REP (i, 0, n) { if (xe[i].FI != prv) { prv = xe[i].FI; ptr++; } inv[ptr] = xe[i].FI; xe[i].FI = ptr; } sort(ALL(ord), greater<ii>()); REP (i, 0, 4 * MAXN) { add[i] = sub[i] = -INF; } for (auto [_, i] : ord) { auto [x, e] = xe[i]; cerr << x << ' ' << e << ' ' << inv[x] << '\n'; cerr << " ? " << e - inv[x] << ' ' << e + inv[x] << '\n'; int sub = qsub(x, n); cerr << ' ' << sub << '\n'; if (sub >= e - inv[x]) { continue; } int add = qadd(1, x); cerr << ' ' << add << '\n'; if (add >= e + inv[x]) { continue; } cerr << " ! " << x << ' ' << e - inv[x] << ' ' << e + inv[x] << '\n'; upd(x, e - inv[x], e + inv[x]); ans++; } cout << ans << '\n'; return 0; }

Compilation message (stderr)

Main.cpp: In function 'void upd(int, int, int, int, int, int)':
Main.cpp:44:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   44 | #define MLR int mid = lo + hi >> 1, lc = u << 1, rc = u << 1 ^ 1
      |                       ~~~^~~~
Main.cpp:52:5: note: in expansion of macro 'MLR'
   52 |     MLR;
      |     ^~~
Main.cpp: In function 'int qsub(int, int, int, int, int)':
Main.cpp:44:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   44 | #define MLR int mid = lo + hi >> 1, lc = u << 1, rc = u << 1 ^ 1
      |                       ~~~^~~~
Main.cpp:66:5: note: in expansion of macro 'MLR'
   66 |     MLR;
      |     ^~~
Main.cpp: In function 'int qadd(int, int, int, int, int)':
Main.cpp:44:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   44 | #define MLR int mid = lo + hi >> 1, lc = u << 1, rc = u << 1 ^ 1
      |                       ~~~^~~~
Main.cpp:80:5: note: in expansion of macro 'MLR'
   80 |     MLR;
      |     ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...