Submission #1118689

#TimeUsernameProblemLanguageResultExecution timeMemory
1118689IcelastAdvertisement 2 (JOI23_ho_t2)C++17
0 / 100
1 ms352 KiB
#include <iostream> #include <bits/stdc++.h> #define ll long long using namespace std; const ll maxn = 2*1e5+5, INF = 4e18+9; struct people{ ll x, e, id; }; struct segment{ ll l, r; }; struct normalize{ vector<ll> poi, pot; void add(ll x){ poi.push_back(x); } void start(){ sort(poi.begin(), poi.end()); if(poi.size() > 0) pot.push_back(poi[0]); for(int i = 1; i < (int)poi.size(); i++){ if(poi[i] != poi[i-1]){ pot.push_back(poi[i]); } } } int encode(ll x){ return lower_bound(pot.begin(), pot.end(), x) - pot.begin()+1; } }; template <class T> struct Fenwick { int n, log; vector<T> bit; Fenwick(int n) : n(n), log(32 - __builtin_clz(n + 1)), bit(n + 1, 0) {} void add(int i, T delta) { for (; i <= n; i += i & -i) { bit[i] += delta; } } T sum(int i) { T res = 0; for (; i > 0; i -= i & -i) { res += bit[i]; } return res; } T sum(int l, int r) { return sum(r)-sum(l-1); } int kth(T k) { T sum = 0; int pos = 0; for (int l = log - 1; l >= 0; l--) { if (pos + (1 << l) <= n && sum + bit[pos + (1 << l)] <= k) { pos += 1 << l; sum += bit[pos]; } } return pos; } }; void solve(){ int n; cin >> n; vector<people> a(n+1); for(int i = 1; i <= n; i++){ cin >> a[i].x >> a[i].e; a[i].id = i; } sort(a.begin()+1, a.end(), [&](people a, people b){return a.e < b.e || (a.e == b.e && a.x < b.x);}); vector<segment> s(1); normalize norm; for(int i = 1; i <= n; i++){ s.push_back({a[i].x-a[i].e, a[i].x+a[i].e}); norm.add(s[i].l); norm.add(s[i].r); } norm.start(); for(int i = 1; i <= n; i++){ s[i] = {norm.encode(s[i].l), norm.encode(s[i].r)}; } int N = norm.pot.size(); Fenwick<int> bit(N+1); sort(s.begin()+1, s.end(), [&](segment a, segment b){return a.l > b.l;}); int ans = 0; for(int i = 1; i <= n; i++){ if(!bit.sum(s[i].r, N)){ ans++; } bit.add(s[i].r, 1); } cout << ans; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); 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...