답안 #1116455

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1116455 2024-11-21T16:47:24 Z epicci23 Trampoline (info1cup20_trampoline) C++17
0 / 100
1092 ms 69740 KB
#include "bits/stdc++.h"
#define int long long
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
using namespace std;


void _(){
  int r,c,n;
  cin >> r >> c >> n;
  array<int,2> ar[n+5];
  for(int i=1;i<=n;i++) cin >> ar[i][0] >> ar[i][1];
  map<int,vector<int>> mp;
  map<array<int,2>,int> rev;
  for(int i=1;i<=n;i++) rev[ar[i]]=i;
  for(int i=1;i<=n;i++) mp[ar[i][0]].push_back(ar[i][1]);
  
  for(auto x : mp) sort(all(mp[x.first]));
  int lift[n+5][20];
  
  
  for(int i=1;i<=n;i++){
  	int a=ar[i][0],b=ar[i][1];
  	int it = lower_bound(all(mp[a+1]),b) - mp[a+1].begin();
  	if(it == sz(mp[a+1])) lift[i][0] = i;
  	else lift[i][0] =  rev[{a+1,mp[a+1][it]}];
  }

  for(int j=1;j<20;j++){
   for(int i=1;i<=n;i++){
    lift[i][j]=lift[lift[i][j-1]][j-1]; 
   }
  }

  int q; cin >> q;
  while(q--){
  	int a,b,c,d;
  	cin >> a >> b >> c >> d;
  	if(a==c){
  	  if(b<=d) cout << "Yes\n";
  	  else cout << "No\n";
  	  continue;
  	}
  	if(a>c){
  	  cout << "No\n";
  	  continue;
  	}
  	int it = lower_bound(all(mp[a]),b) - mp[a].begin();
  	if(it == sz(mp[a])){
  	  cout << "No\n";
  	  continue;
  	}
  	int p = rev[{a,mp[a][it]}];
  	for(int i=19;i>=0;i--){
      int A = ar[lift[p][i]][0];
      int B = ar[lift[p][i]][1];
      if(A>c) continue;
      p = lift[p][i];
  	}
  	if(ar[p][0] + 1 < c){
     cout << "No\n";
     continue;
  	}
  	if(ar[p][1] <= d) cout << "Yes\n";
  	else cout << "No\n";
  }
}

int32_t main(){
  ios::sync_with_stdio(0); cin.tie(0);
  int tc=1;//cin >> tc;
  while(tc--) _();
}

Compilation message

trampoline.cpp: In function 'void _()':
trampoline.cpp:56:11: warning: unused variable 'B' [-Wunused-variable]
   56 |       int B = ar[lift[p][i]][1];
      |           ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 2640 KB expected YES, found NO [68th token]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 332 ms 52296 KB expected YES, found NO [1822nd token]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 529 ms 62500 KB expected YES, found NO [4th token]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 1872 KB expected YES, found NO [1st token]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1092 ms 69740 KB expected YES, found NO [1st token]
2 Halted 0 ms 0 KB -