#include<bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) ((int) x.size())
#define pb(x) push_back(x)
typedef long long ll;
typedef pair<int, int> point;
const int inf = 1e9 + 5;
int n, m;
set <int> up, down, revUp, revDown;
set <point> mostUp, mostDown;
bool istiUp(int x, int y){
if(x > y) return false;
int sol = *up.lower_bound(x);
if(sol < y) return false;
return true;
}
bool istiDown(int x, int y){
if(x < y) return false;
int sol = *down.lower_bound(-y);
sol = -sol;
if(sol > y) return false;
return true;
}
bool query(int x, int y){
if(x == y) return true;
if (x <= n && y <= n){
if(x < y) return istiUp(x, y);
auto it = *mostUp.lower_bound(point(x, -inf));
int block = *up.lower_bound(x);
if(block < it.first) return false;
return query(it.second, y);
}
else if(x > n && y > n){
if(x > y) return istiDown(x, y);
auto it = *mostDown.lower_bound(point(-x, -inf));
int block = *down.lower_bound(-x); block = -block;
if(block > it.first) return false;
return query(it.second, y);
}
else if(x <= n){
bool ret1 = false, ret2 = false;
auto gore = mostUp.lower_bound(point(x, -inf));
if(gore != mostUp.end()){
auto it1 = *up.lower_bound(x);
if(it1 >= (*gore).first)
ret1 = istiDown((*gore).second, y);
}
auto dole = mostDown.lower_bound(point(y, -inf));
auto it2 = *down.lower_bound(-(*dole).first); it2 = -it2;
if(it2 <= y)
ret2 = istiUp(x, (*dole).second);
return (ret1 | ret2);
}
else if(x > n){
bool ret1 = false, ret2 = false;
auto dole = mostDown.upper_bound(point(x, inf));
if(dole != mostDown.begin()){
dole --;
auto it1 = down.upper_bound(-x);
auto it = *it1;
if(it1 != down.begin()){
it1 --; it = *it1; it = -it;
}
else
it = -1;
if(it <= (*dole).first)
ret1 = query((*dole).second, y);
}
auto gore = mostUp.upper_bound(point(y, inf));
auto it2 = up.upper_bound(y);
auto it3 = *it2;
if(it2 == up.begin())
it3 = inf;
else{
it2 --; it3 = *it2;
}
if(gore != mostUp.begin()){
gore --;
if((*gore).first <= it3)
ret2 = query(x, (*gore).second);
}
return (ret1 | ret2);
}
assert(n == 0);
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
up.insert(inf); down.insert(inf); revUp.insert(inf); revDown.insert(inf); mostUp.insert(point(inf, 0)); mostDown.insert(point(inf, 0));
cin >> n >> m;
REP(i, m){
char tip; cin >> tip;
int x, y; cin >> x >> y;
if(tip == 'A'){
if(x > n){
mostDown.insert(point(x, y));
mostUp.insert(point(y, x));
}
else{
mostDown.insert(point(y, x));
mostUp.insert(point(x, y));
}
}
else if(tip == 'B'){
if(x > n){
down.insert(-max(x, y));
revDown.insert(min(x, y));
}
else{
up.insert(min(x, y));
revUp.insert(-max(x, y));
}
}
else{
if(query(x, y)) cout << "DA\n";
else cout << "NE\n";
}
}
}
Compilation message
mostovi.cpp: In function 'bool query(int, int)':
mostovi.cpp:102:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
294 ms |
263168 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Runtime error |
380 ms |
263168 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
3 |
Runtime error |
343 ms |
263168 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
4 |
Runtime error |
292 ms |
263168 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
5 |
Runtime error |
385 ms |
263168 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
6 |
Runtime error |
2 ms |
263168 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
7 |
Runtime error |
218 ms |
263168 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
8 |
Runtime error |
270 ms |
263168 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
9 |
Runtime error |
351 ms |
263168 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
10 |
Runtime error |
384 ms |
263168 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |