제출 #1094067

#제출 시각아이디문제언어결과실행 시간메모리
1094067stefanopulosAdvertisement 2 (JOI23_ho_t2)C++17
100 / 100
488 ms18448 KiB
#include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <bits/stdc++.h> using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ldb; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef pair<ldb,ldb> pdd; #define ff(i,a,b) for(int i = a; i <= b; i++) #define fb(i,b,a) for(int i = b; i >= a; i--) #define trav(a,x) for(auto& a : x) #define sz(a) (int)(a).size() #define fi first #define se second #define pb push_back #define lb lower_bound #define ub upper_bound #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // os.order_of_key(k) the number of elements in the os less than k // *os.find_by_order(k) print the k-th smallest number in os(0-based) const int mod = 1000000007; const int inf = 2e9 + 5; const int mxN = 500005; int n; pii niz[mxN]; int id1[mxN]; bool cmp1(int i, int j){ return niz[i].fi < niz[j].fi; } int id2[mxN]; bool cmp2(int i, int j){ return niz[i].se > niz[j].se; } int pos[mxN]; struct SegTreeMX{ int bor[4 * mxN]; void build(int v, int tl, int tr){ bor[v] = -inf; if(tl == tr)return; int mid = (tl + tr) / 2; build(v * 2, tl, mid); build(v * 2 + 1, mid + 1, tr); } void update(int v, int tl, int tr, int pos, int val){ if(tl == tr){ bor[v] = val; return; } int mid = (tl + tr) / 2; if(pos <= mid)update(v * 2, tl, mid, pos, val); else update(v * 2 + 1, mid + 1, tr, pos, val); bor[v] = max(bor[v * 2], bor[v * 2 + 1]); } int kveri(int v, int tl, int tr, int l, int r){ if(tl > r || l > tr)return -inf; if(tl >= l && tr <= r)return bor[v]; int mid = (tl + tr) / 2; return max(kveri(v * 2, tl, mid, l, r), kveri(v * 2 + 1, mid + 1, tr, l, r)); } }MX; struct SegTreeMN{ int bor[4 * mxN]; void build(int v, int tl, int tr){ bor[v] = inf; if(tl == tr)return; int mid = (tl + tr) / 2; build(v * 2, tl, mid); build(v * 2 + 1, mid + 1, tr); } void update(int v, int tl, int tr, int pos, int val){ if(tl == tr){ bor[v] = val; return; } int mid = (tl + tr) / 2; if(pos <= mid)update(v * 2, tl, mid, pos, val); else update(v * 2 + 1, mid + 1, tr, pos, val); bor[v] = min(bor[v * 2], bor[v * 2 + 1]); } int kveri(int v, int tl, int tr, int l, int r){ if(tl > r || l > tr)return inf; if(tl >= l && tr <= r)return bor[v]; int mid = (tl + tr) / 2; return min(kveri(v * 2, tl, mid, l, r), kveri(v * 2 + 1, mid + 1, tr, l, r)); } }MN; int main(){ cin.tie(0)->sync_with_stdio(0); cin >> n; ff(i,1,n)cin >> niz[i].fi >> niz[i].se; ff(i,1,n)id1[i] = id2[i] = i; sort(id1 + 1, id1 + n + 1, cmp1); sort(id2 + 1, id2 + n + 1, cmp2); ff(i,1,n)pos[id1[i]] = i; int br = 0; MX.build(1,1,n); MN.build(1,1,n); ff(i,1,n){ int X = niz[id2[i]].fi; int E = niz[id2[i]].se; int L = MX.kveri(1,1,n,1,pos[id2[i]]); int R = MN.kveri(1,1,n,pos[id2[i]],n); if(X + E > L && R > X - E){ br += 1; } MX.update(1,1,n,pos[id2[i]],X + E); MN.update(1,1,n,pos[id2[i]],X - E); } cout << br << '\n'; return 0; } /* 4 4 2 2 3 3 4 6 5 // probati bojenje sahovski */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...