#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 = 2e9 + 5;
int n, m;
set <int> up, down;
set <point> mostUp, mostDown;
bool istiUp(int x, int y){
if(x > y) return false;
auto it = up.upper_bound(x);
if(y < *it) return true;
return false;
}
bool istiDown(int x, int y){
if(x < y) return false;
auto it = down.lower_bound(x); it --;
if(y > *it) return true;
return false;
}
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));
auto block = up.upper_bound(x);
if(it != mostUp.end() && *block > (*it).first)
return query((*it).second, y);
else
return false;
}
else if( x > n && y > n ){
if(x > y) return istiDown(x, y);
auto it = mostDown.lower_bound(point(x, inf));
if(it == mostDown.begin()) return false;
it --;
auto block = down.lower_bound(x); block --;
if((*it).first > *block)
return query((*it).second, y);
else
return false;
}
else if( x <= n ){
bool ret1 = false, ret2 = false;
auto it1 = mostUp.lower_bound(point(x, -inf));
auto block = up.upper_bound(x);
if((*it1).first < *block)
ret1 = istiDown((*it1).second, y);
auto it2 = mostDown.lower_bound(point(y, -inf));
auto block2 = down.lower_bound(y);
if( it2 != mostDown.end()){
if((*it2).first == y || (*it2).first < *block2)
ret2 = istiUp(x, (*it2).second);
}
return (ret1 | ret2);
}
else if( x > n ){
bool ret1 = false, ret2 = false;
auto it1 = mostDown.lower_bound(point(x, inf));
if(it1 != mostDown.begin()){
it1 --;
auto block = down.lower_bound(x); block --;
if((*it1).first > *block)
ret1 = istiUp((*it1).second, y);
}
auto it2 = mostUp.lower_bound(point(x, inf));
if(it2 != mostUp.begin()){
it2 --;
auto block = up.upper_bound((*it1).first);
if(y < *block)
ret2 = istiDown(x, (*it2).second);
}
return (ret1 | ret2);
}
assert(n == 0);
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
up.insert(inf); down.insert(inf);
up.insert(-inf); down.insert(-inf);
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(min(x, y));
}
else{
up.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:99:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Incorrect |
2 ms |
408 KB |
Output isn't correct |
4 |
Incorrect |
2 ms |
440 KB |
Output isn't correct |
5 |
Incorrect |
2 ms |
592 KB |
Output isn't correct |
6 |
Correct |
2 ms |
592 KB |
Output is correct |
7 |
Incorrect |
178 ms |
12364 KB |
Output isn't correct |
8 |
Incorrect |
222 ms |
16880 KB |
Output isn't correct |
9 |
Incorrect |
210 ms |
21304 KB |
Output isn't correct |
10 |
Incorrect |
264 ms |
28172 KB |
Output isn't correct |