Submission #90704

# Submission time Handle Problem Language Result Execution time Memory
90704 2018-12-23T20:01:33 Z Milki Mostovi (COI14_mostovi) C++14
100 / 100
270 ms 10196 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 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(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:99: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 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 440 KB Output is correct
4 Correct 2 ms 440 KB Output is correct
5 Correct 2 ms 500 KB Output is correct
6 Correct 2 ms 648 KB Output is correct
7 Correct 173 ms 7876 KB Output is correct
8 Correct 204 ms 7888 KB Output is correct
9 Correct 175 ms 7904 KB Output is correct
10 Correct 270 ms 10196 KB Output is correct