답안 #537328

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
537328 2022-03-15T01:54:15 Z cig32 Trampoline (info1cup20_trampoline) C++17
100 / 100
921 ms 93656 KB
#include "bits/stdc++.h"
using namespace std;
const int MAXN = 1e6 + 10;
const int MOD = 1e9 + 7;
#define int long long
 
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x, int y) {
  int u = uniform_int_distribution<int>(x, y)(rng); return u;
}
long long bm(long long b, long long p) { 
  if(p==0) return 1;
  long long r = bm(b, p/2);
  if(p&1) return (((r*r) % MOD) * b) % MOD;
  return (r*r) % MOD;
}


void solve(int tc) {
  int r, c, n;
  cin >> r >> c >> n;
  unordered_map<int, set<int> > mp;
  int x[n+1], y[n+1];
  map<pair<int, int>, int> id;
  for(int i=1; i<=n; i++) {
    cin >> x[i] >> y[i];
    id[{x[i], y[i]}] = i;
    mp[x[i]].insert(y[i]);
    mp[x[i] + 1].insert(MOD);
  }

  int st[18][n+1];
  for(int i=1; i<=n; i++) {
    auto it = mp[x[i] + 1].lower_bound(y[i]);
    if((*it) != MOD) {
      int wow = id[{x[i] + 1, (*it)}];
      st[0][i] = wow;
    }
    else {
      st[0][i] = -1;
    }
  }
  for(int i=1; i<18; i++) {
    for(int j=1; j<=n; j++) {
      if(st[i-1][j] == -1) st[i][j] = -1;
      else st[i][j] = st[i-1][st[i-1][j]];
    }
  }
  int t;
  cin >> t;
  while(t--) {
    int xs, ys, xe, ye;
    cin >> xs >> ys >> xe >> ye;
    if(!(xs <= xe && ys <= ye)) {
      cout << "No\n";
      continue;
    }
    if(xs == xe) {
      cout << "Yes\n";
      continue;
    }
    int k = xe - xs - 1;
    mp[xs].insert(MOD);
    auto it = mp[xs].lower_bound(ys);
    int stt;
    if((*it) != MOD) {
      stt = id[{xs, (*it)}];
    }
    else {
      cout << "No\n"; 
      continue;
    }
    bool gg = 0;
    for(int j=17; j>=0; j--) {
      if(k >= (1<<j)) {
        k -= (1<<j);
        stt = st[j][stt];
        if(stt == -1) {
          cout << "No\n";
          gg = 1;
          break;
        } 
      }
    }
    if(!gg) {
      if(y[stt] <= ye) {
        cout << "Yes\n";
      }
      else {
        cout << "No\n";
      }
    }
  }
}

int32_t main(){
  ios::sync_with_stdio(0); cin.tie(0);
  int t = 1; //cin >> t;
  for(int i=1; i<=t; i++) solve(i);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 2644 KB 200 token(s): yes count is 21, no count is 179
2 Correct 10 ms 3076 KB 200 token(s): yes count is 70, no count is 130
3 Correct 6 ms 2260 KB 197 token(s): yes count is 25, no count is 172
# 결과 실행 시간 메모리 Grader output
1 Correct 420 ms 55640 KB 4000 token(s): yes count is 99, no count is 3901
2 Correct 456 ms 55740 KB 4000 token(s): yes count is 91, no count is 3909
3 Correct 438 ms 55188 KB 4000 token(s): yes count is 4000, no count is 0
4 Correct 434 ms 55664 KB 4000 token(s): yes count is 1991, no count is 2009
# 결과 실행 시간 메모리 Grader output
1 Correct 609 ms 65872 KB 200000 token(s): yes count is 110486, no count is 89514
2 Correct 626 ms 66080 KB 200000 token(s): yes count is 114664, no count is 85336
3 Correct 656 ms 65912 KB 200000 token(s): yes count is 86232, no count is 113768
4 Correct 700 ms 66292 KB 200000 token(s): yes count is 94603, no count is 105397
5 Correct 677 ms 66212 KB 200000 token(s): yes count is 94148, no count is 105852
6 Correct 737 ms 74888 KB 200000 token(s): yes count is 97163, no count is 102837
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 1876 KB 5000 token(s): yes count is 3238, no count is 1762
2 Correct 9 ms 1972 KB 5000 token(s): yes count is 3837, no count is 1163
3 Correct 9 ms 3156 KB 5000 token(s): yes count is 4104, no count is 896
4 Correct 8 ms 1968 KB 5000 token(s): yes count is 3934, no count is 1066
5 Correct 9 ms 2132 KB 5000 token(s): yes count is 3384, no count is 1616
6 Correct 7 ms 1956 KB 5000 token(s): yes count is 3390, no count is 1610
# 결과 실행 시간 메모리 Grader output
1 Correct 900 ms 76524 KB 200000 token(s): yes count is 171404, no count is 28596
2 Correct 806 ms 68648 KB 200000 token(s): yes count is 161254, no count is 38746
3 Correct 661 ms 66016 KB 200000 token(s): yes count is 117455, no count is 82545
4 Correct 921 ms 93656 KB 200000 token(s): yes count is 182118, no count is 17882
5 Correct 747 ms 75516 KB 200000 token(s): yes count is 167565, no count is 32435
6 Correct 727 ms 65936 KB 200000 token(s): yes count is 156797, no count is 43203
7 Correct 699 ms 66120 KB 200000 token(s): yes count is 156797, no count is 43203
8 Correct 656 ms 66040 KB 200000 token(s): yes count is 122100, no count is 77900
9 Correct 839 ms 75076 KB 200000 token(s): yes count is 139670, no count is 60330
10 Correct 858 ms 75096 KB 200000 token(s): yes count is 165806, no count is 34194
11 Correct 908 ms 84096 KB 200000 token(s): yes count is 175646, no count is 24354
12 Correct 531 ms 65948 KB 200000 token(s): yes count is 134695, no count is 65305
13 Correct 568 ms 66192 KB 200000 token(s): yes count is 126733, no count is 73267
14 Correct 767 ms 66172 KB 200000 token(s): yes count is 155290, no count is 44710
15 Correct 608 ms 65900 KB 200000 token(s): yes count is 129674, no count is 70326