# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
90699 | Milki | Mostovi (COI14_mostovi) | C++14 | 212 ms | 10232 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 true;
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 true;
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));
if(it1 != mostUp.end()){
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(y, inf));
if(it2 != mostUp.begin()){
it2 --;
auto block = up.upper_bound((*it2).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";
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |