Submission #493328

#TimeUsernameProblemLanguageResultExecution timeMemory
493328ntabc05101Mostovi (COI14_mostovi)C++14
100 / 100
186 ms14332 KiB
#include<bits/stdc++.h> using namespace std; int n, m; set<int> bl; set< array<int, 2> > sx, sy; array<int, 2> getR(int x, int y) { auto it = sx.lower_bound({x, -1}); if (it != sx.end() && (*it)[1] >= y) { return *it; } it = sy.lower_bound({y, -1}); if (it != sy.end() && (*it)[1] >= x) { return {(*it)[1], (*it)[0]}; } return {-1, -1}; } array<int, 2> getL(int x, int y) { auto it = sx.lower_bound({x + 1, -1}); if (it != sx.begin()) { it--; if ((*it)[1] <= y) { return *it; } } it = sy.lower_bound({y + 1, -1}); if (it != sy.begin()) { it--; if ((*it)[1] <= x) { return {(*it)[1], (*it)[0]}; } } return {-1, -1}; } bool chk(int x, int y) { if (!(~x) || !(~y)) { return false; } if (x == y) { return true; } if (x < n && y < n) { if (x < y) { auto it = bl.lower_bound(x); return it == bl.end() || *it >= y; } else { auto m = getR(x, -1); return (chk(x, m[0]) && chk(m[1], y)); } } if (x >= n && y >= n) { if (x > y) { auto it = bl.lower_bound(y); return it == bl.end() || *it >= x; } else { auto m = getL(n, x); return chk(x, m[1]) && chk(m[0], y); } } if (x < n) { auto m = getR(x, y); return chk(x, m[0]) && chk(m[1], y); } else { auto m = getL(y, x); return chk(x, m[1]) && chk(m[0], y); } return false; } int main() { cin.tie(0)->sync_with_stdio(0); cin >> n >> m; for (int i = 0; i < m; i++) { char type; int x, y; cin >> type >> x >> y; x--; y--; if (type == 'Q') { cout << (chk(x, y) ? "DA": "NE") << "\n"; } else { if (x > y) { swap(x, y); } if (type == 'A') { sx.insert({x, y}); sy.insert({y, x}); } else { bl.insert(x); } } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...