# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
493328 | ntabc05101 | Mostovi (COI14_mostovi) | C++14 | 186 ms | 14332 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |