Submission #957535

#TimeUsernameProblemLanguageResultExecution timeMemory
957535VinhLuuAdvertisement 2 (JOI23_ho_t2)C++17
100 / 100
1468 ms108008 KiB
#include <bits/stdc++.h> #define int long long #define ll long long #define fi first #define se second #define pb push_back #define all(lmao) lmao.begin(), lmao.end() using namespace std; typedef pair<int,int> pii; typedef tuple<int,int,int> tp; const int N = 1e6 + 5; const int mod = 1e9 + 7; const int oo = 2e18; int px[N], py[N], tx, ty, n, X[N], E[N], c[N], f[N], b[N], t; int st[N << 1]; void update(int i){ i += n - 1; st[i]++; while(i > 1){ i /= 2; st[i]++; } } int get(int l,int r){ if(l > r) return 0; r++; int ret = 0; for(l += n - 1, r += n - 1; l < r; l /= 2, r /= 2){ if(l & 1) ret += st[l++]; if(r & 1) ret += st[--r]; } return ret; } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define task "v" if(fopen(task ".inp","r")){ freopen(task ".inp","r",stdin); freopen(task ".out","w",stdout); } cin >> n; for(int i = 1; i <= n; i ++){ cin >> X[i] >> E[i]; b[i] = i; } sort(b + 1, b + n + 1, [&] (int x,int y){return X[x] == X[y] ? E[x] < E[y] : X[x] < X[y];}); t++; c[t] = b[1]; for(int i = 2; i <= n; i ++){ if(E[b[i]] == E[b[i - 1]] && X[b[i]] == X[b[i - 1]]) continue; t++; c[t] = b[i]; } n = t; set<int> sx, sy; for(int i = 1; i <= n; i ++){ sx.insert(X[c[i]] + E[c[i]]); sy.insert(X[c[i]] - E[c[i]]); } for(auto j : sx) px[++tx] = j; for(auto j : sy) py[++ty] = j; for(int k = 1; k <= n; k ++){ int i = c[k]; int w = lower_bound(px + 1, px + tx + 1, X[i] + E[i]) - px; f[k] += get(w, n); update(w); } for(int i = 1; i <= 2 * n; i ++) st[i] = 0; for(int k = n; k >= 1; k --){ int i = c[k]; int w = lower_bound(py + 1, py + ty + 1, X[i] - E[i]) - py; f[k] += get(1, w); update(w); } int ans = 0; for(int i = 1; i <= n; i ++) if(!f[i]) ans++; cout << ans; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:47:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |         freopen(task ".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:48:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |         freopen(task ".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...