Submission #90699

#TimeUsernameProblemLanguageResultExecution timeMemory
90699MilkiMostovi (COI14_mostovi)C++14
60 / 100
212 ms10232 KiB
#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"; } } }

Compilation message (stderr)

mostovi.cpp: In function 'bool query(int, int)':
mostovi.cpp:102:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
#Verdict Execution timeMemoryGrader output
Fetching results...