Submission #90688

#TimeUsernameProblemLanguageResultExecution timeMemory
90688MilkiMostovi (COI14_mostovi)C++14
0 / 100
385 ms263168 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 = 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 (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...