답안 #993816

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
993816 2024-06-06T12:54:03 Z kachim2 Trampoline (info1cup20_trampoline) C++17
100 / 100
1256 ms 89316 KB
#include <algorithm>
#include<vector>
#include<iostream>
#include<unordered_map>
//#include <bits/stdc++.h>
#include <cstdio>
#include <valarray>
#include <variant>
#include <assert.h>
using namespace std;

struct trampoline {
  long x, y;
  vector<trampoline *> jp;
  bool isjp = 0;
  friend bool operator<(const trampoline &l, const trampoline &r) {
    return l.x < r.x;
  }
  void genjp();
};
unordered_map<long, vector<trampoline >> trampolines;
void trampoline::genjp() {
  if (isjp)
    return;
  isjp = 1;
  trampoline *next;
  if (!trampolines.count(y + 1))
    return;

  auto &a = trampolines[y + 1];
  auto b = lower_bound(a.begin(), a.end(), *this);
  if (b == a.end()) {
    return;
  }
  next = &*b;
  jp.push_back(next);
  while (true) {
    (*jp.rbegin())->genjp();
    if (this->jp.size() > (*jp.rbegin())->jp.size()) {
      return;
    }
    jp.push_back((*jp.rbegin())->jp[this->jp.size() - 1]);
  }
}
int main() {
  int R, C, N;
  cin >> R >> C >> N;

  vector<trampoline *> tramps;
  
    
  for (int i = 0; i < N; i++) {
    int x, y;
    cin >> y >> x;

    trampolines[y].emplace_back();
    (*trampolines[y].rbegin()).x = x;
    (*trampolines[y].rbegin()).y = y;
    tramps.push_back(&*trampolines[y].rbegin());
  }
  for (auto &[key, i] : trampolines) {
    sort(i.begin(), i.end());
  }
  for (auto &[key, j] : trampolines){
  for (auto &i : j) {
    i.genjp();
  }
  }
  int T;
  cin >> T;
  for (int i = 0; i < T; i++){
    //if(i!=0)cout << '\n';
    long x1, x2, y1, y2;
    cin >> y1 >> x1 >> y2 >> x2;
    if(y1 == y2 and x1 <= x2){
      cout << "Yes\n";
      continue;
    }
    trampoline tmptramp;
    tmptramp.x = x1;
    auto tc = lower_bound(trampolines[y1].begin(), trampolines[y1].end(), tmptramp);
    if(tc == trampolines[y1].end()){
      cout << "No\n";
      continue;
      
    }
    trampoline *curr = &*tc;
    int v = y2-y1-1;
    for(int j = 0; v!=0; j++){
      if(v&1){
      if(curr->jp.size() <= j) goto no;
      curr = curr->jp[j];
      }
     v>>=1;
    }
    if(curr->x > x2){
      goto no;
    }
    goto yes;
  no:
    cout << "No\n";
    continue;
  yes:
    cout << "Yes\n";
  }

 
}

Compilation message

trampoline.cpp: In function 'int main()':
trampoline.cpp:91:26: warning: comparison of integer expressions of different signedness: 'std::vector<trampoline*>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   91 |       if(curr->jp.size() <= j) goto no;
      |          ~~~~~~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1624 KB 200 token(s): yes count is 21, no count is 179
2 Correct 7 ms 1884 KB 200 token(s): yes count is 70, no count is 130
3 Correct 4 ms 1424 KB 197 token(s): yes count is 25, no count is 172
# 결과 실행 시간 메모리 Grader output
1 Correct 153 ms 32960 KB 4000 token(s): yes count is 99, no count is 3901
2 Correct 139 ms 32960 KB 4000 token(s): yes count is 91, no count is 3909
3 Correct 140 ms 35960 KB 4000 token(s): yes count is 4000, no count is 0
4 Correct 130 ms 38588 KB 4000 token(s): yes count is 1991, no count is 2009
# 결과 실행 시간 메모리 Grader output
1 Correct 601 ms 33824 KB 200000 token(s): yes count is 110486, no count is 89514
2 Correct 601 ms 39320 KB 200000 token(s): yes count is 114664, no count is 85336
3 Correct 699 ms 35516 KB 200000 token(s): yes count is 86232, no count is 113768
4 Correct 666 ms 53436 KB 200000 token(s): yes count is 94603, no count is 105397
5 Correct 652 ms 53700 KB 200000 token(s): yes count is 94148, no count is 105852
6 Correct 792 ms 60504 KB 200000 token(s): yes count is 97163, no count is 102837
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 1116 KB 5000 token(s): yes count is 3238, no count is 1762
2 Correct 15 ms 1372 KB 5000 token(s): yes count is 3837, no count is 1163
3 Correct 19 ms 1368 KB 5000 token(s): yes count is 4104, no count is 896
4 Correct 16 ms 1116 KB 5000 token(s): yes count is 3934, no count is 1066
5 Correct 17 ms 1884 KB 5000 token(s): yes count is 3384, no count is 1616
6 Correct 15 ms 1112 KB 5000 token(s): yes count is 3390, no count is 1610
# 결과 실행 시간 메모리 Grader output
1 Correct 1112 ms 66452 KB 200000 token(s): yes count is 171404, no count is 28596
2 Correct 816 ms 57816 KB 200000 token(s): yes count is 161254, no count is 38746
3 Correct 656 ms 35048 KB 200000 token(s): yes count is 117455, no count is 82545
4 Correct 1137 ms 89316 KB 200000 token(s): yes count is 182118, no count is 17882
5 Correct 754 ms 48168 KB 200000 token(s): yes count is 167565, no count is 32435
6 Correct 679 ms 40496 KB 200000 token(s): yes count is 156797, no count is 43203
7 Correct 698 ms 39980 KB 200000 token(s): yes count is 156797, no count is 43203
8 Correct 654 ms 33832 KB 200000 token(s): yes count is 122100, no count is 77900
9 Correct 1030 ms 61192 KB 200000 token(s): yes count is 139670, no count is 60330
10 Correct 1043 ms 62296 KB 200000 token(s): yes count is 165806, no count is 34194
11 Correct 1256 ms 77360 KB 200000 token(s): yes count is 175646, no count is 24354
12 Correct 630 ms 30920 KB 200000 token(s): yes count is 134695, no count is 65305
13 Correct 633 ms 34548 KB 200000 token(s): yes count is 126733, no count is 73267
14 Correct 813 ms 52160 KB 200000 token(s): yes count is 155290, no count is 44710
15 Correct 646 ms 33320 KB 200000 token(s): yes count is 129674, no count is 70326