# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
90702 |
2018-12-23T19:55:20 Z |
Milki |
Mostovi (COI14_mostovi) |
C++14 |
|
222 ms |
10168 KB |
#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()) return false;
auto block = up.upper_bound(x);
if((*it1).first < *block || (*it1).first == x)
ret1 = istiDown((*it1).second, y);
auto it2 = mostDown.lower_bound(point(y, -inf));
if(it2 == mostDown.end()) return false;
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";
}
}
}
Compilation message
mostovi.cpp: In function 'bool query(int, int)':
mostovi.cpp:103:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
508 KB |
Output isn't correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
190 ms |
7832 KB |
Output is correct |
8 |
Incorrect |
222 ms |
8112 KB |
Output isn't correct |
9 |
Incorrect |
187 ms |
8112 KB |
Output isn't correct |
10 |
Incorrect |
220 ms |
10168 KB |
Output isn't correct |