Submission #1170610

#TimeUsernameProblemLanguageResultExecution timeMemory
1170610lopkusTrampoline (info1cup20_trampoline)C++20
0 / 100
2096 ms26544 KiB
#include <bits/stdc++.h>

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int r, c, n;
  std::cin >> r >> c >> n;
  std::vector<std::pair<int,int>> a(n + 1);
  for(int i = 1; i <= n; i++) {
    std::cin >> a[i].first >> a[i].second;
  }
  std::sort(a.begin() + 1, a.end());
  std::map<std::pair<int,int>, int> M;
  std::vector<int> next(n + 1, 0);
  for(int i = 1; i <= n; i++) {
    for(int j = i + 1; j <= n; j++) {
      if(a[i].first + 1 == a[j].first && a[i].second <= a[j].second) {
        next[i] = j;
        break;
      }
    }
  }
  std::vector<std::vector<int>> jump(n + 1, std::vector<int>(21));
  for(int i = 1; i <= n; i++) {
    jump[i][0] = next[i];
  }
  for(int j = 1; j < 20; j++){
		for(int i = 1; i <= n; i++){
			jump[i][j] = jump[jump[i][j - 1]][j - 1];
		}
	}
  int q;
  std::cin >> q;
  while(q--) {
    int x1, y1, x2, y2;
    std::cin >> x1 >> y1 >> x2 >> y2;
    if(y1 > y2 || x2 < x1) {
      std::cout << "No\n";
      continue;
    }
    int index = - 1;
    for(int i = 1; i <= n; i++) {
      if(a[i].first == x1 && a[i].second >= y1) {
        index = i;
        break;
      }
    }
    if(index == - 1) {
      if(x1 != x2) {
        std::cout << "No\n";
        continue;
      }
      if(y1 <= y2) {
        std::cout << "Yes\n";
      }
      else {
        std::cout << "No\n";
      }
      continue;
    }
    //std::cout << index << " ";
    for(int bit = 20; bit >= 0; bit--) {
      int to = jump[index][bit];
      if(to > n || to == 0) {
        continue;
      }
      //std::cout << to << " ";
      if(a[to].first < x2 && a[to].second <= y2) {
        index = to;
      }
    }
    if(a[index].first == x2 - 1 && a[index].second <= y2) {
      std::cout << "Yes\n";
    }
    else {
      std::cout << "No\n";
    }
  }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...