Submission #522449

#TimeUsernameProblemLanguageResultExecution timeMemory
522449KoDSunčanje (COCI18_suncanje)C++17
130 / 130
2477 ms117448 KiB
#include <bits/stdc++.h> using std::vector; using std::array; using std::tuple; using std::pair; int dedup(vector<int>& v) { std::sort(v.begin(), v.end()); v.erase(std::unique(v.begin(), v.end()), v.end()); return v.size(); } int lowb(const vector<int>& v, const int x) { return std::lower_bound(v.begin(), v.end(), x) - v.begin(); } struct Fenwick { int size; vector<int> data; Fenwick() = default; Fenwick(const int n) : size(n), data(n + 1) {} void add(int i) { i += 1; while (i <= size) { data[i] += 1; i += i & -i; } } int pref(int i) const { int ret = 0; while (i > 0) { ret += data[i]; i -= i & -i; } return ret; } int fold(const int l, const int r) const { return pref(r) - pref(l); } }; struct Sum2D { int X, Y; vector<vector<int>> pts; vector<Fenwick> fen; Sum2D(const int x, const int y) : X(x), Y(y), pts(X + 1), fen(X + 1) {} void set(int x, int y) { x += 1; while (x <= X) { pts[x].push_back(y); x += x & -x; } } void build() { for (int x = 1; x <= X; ++x) { dedup(pts[x]); fen[x] = Fenwick(pts[x].size()); } } void add(int x, int y) { x += 1; while (x <= X) { fen[x].add(lowb(pts[x], y)); x += x & -x; } } int pref(int x, const int u, const int d) const { int ret = 0; while (x > 0) { ret += fen[x].fold(lowb(pts[x], u), lowb(pts[x], d)); x -= x & -x; } return ret; } int fold(const int l, const int r, const int u, const int d) const { return pref(r, u, d) - pref(l, u, d); } }; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); int N; std::cin >> N; vector<int> A(N), B(N), C(N), D(N); for (int i = 0; i < N; ++i) { int x, y, a, b; std::cin >> x >> y >> a >> b; A[i] = x, B[i] = y, C[i] = x + a, D[i] = y + b; } vector<int> cX, cY; cX.reserve(2 * N); std::copy(A.begin(), A.end(), std::back_inserter(cX)); std::copy(C.begin(), C.end(), std::back_inserter(cX)); std::copy(B.begin(), B.end(), std::back_inserter(cY)); std::copy(D.begin(), D.end(), std::back_inserter(cY)); const int nX = dedup(cX); const int nY = dedup(cY); for (auto& x : A) { x = lowb(cX, x); } for (auto& x : C) { x = lowb(cX, x); } for (auto& y : B) { y = lowb(cY, y); } for (auto& y : D) { y = lowb(cY, y); } Sum2D ld(nX, nY), rd(nX, nY), lu(nX, nY), ru(nX, nY); for (int i = 0; i < N; ++i) { ld.set(C[i], D[i]); rd.set(A[i], D[i]); lu.set(C[i], B[i]); ru.set(A[i], B[i]); } ld.build(); rd.build(); lu.build(); ru.build(); Fenwick l(nX), r(nX), d(nY), u(nY); vector<int> ans(N); for (int i = N - 1; i >= 0; --i) { ans[i] = N - i - 1; ans[i] -= l.fold(0, A[i] + 1); ans[i] -= r.fold(C[i], nX); ans[i] -= d.fold(0, B[i] + 1); ans[i] -= u.fold(D[i], nY); ans[i] += ld.fold(0, A[i] + 1, 0, B[i] + 1); ans[i] += rd.fold(C[i], nX, 0, B[i] + 1); ans[i] += lu.fold(0, A[i] + 1, D[i], nY); ans[i] += ru.fold(C[i], nX, D[i], nY); l.add(C[i]); r.add(A[i]); d.add(D[i]); u.add(B[i]); ld.add(C[i], D[i]); rd.add(A[i], D[i]); lu.add(C[i], B[i]); ru.add(A[i], B[i]); } for (const int c : ans) { std::cout << (c ? "NE" : "DA") << '\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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...