제출 #979131

#제출 시각아이디문제언어결과실행 시간메모리
979131MilosMilutinovicLightning Rod (NOI18_lightningrod)C++14
66 / 100
2075 ms262144 KiB
#include <bits/stdc++.h> using namespace std; template <typename T> class fenwick { public: vector<T> fenw; int n; fenwick(int _n) : n(_n) { fenw.resize(n); } void modify(int x, T v) { while (x < n) { fenw[x] += v; x |= (x + 1); } } T get(int x) { T v{}; while (x >= 0) { v += fenw[x]; x = (x & (x + 1)) - 1; } return v; } }; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> x(n); vector<int> y(n); for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; x[i] = a - b; y[i] = a + b; } vector<int> order(n); iota(order.begin(), order.end(), 0); sort(order.begin(), order.end(), [&](int i, int j) { if (x[i] != x[j]) { return x[i] < x[j]; } else { return y[i] > y[j]; } }); auto xs = y; sort(xs.begin(), xs.end()); xs.erase(unique(xs.begin(), xs.end()), xs.end()); fenwick<int> fenw(n + 1); int ans = 0; for (int i : order) { int v = (int) (lower_bound(xs.begin(), xs.end(), y[i]) - xs.begin()); if (fenw.get(n - v) == 0) { ans += 1; fenw.modify(n - v, +1); } } cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...