Submission #1116456

# Submission time Handle Problem Language Result Execution time Memory
1116456 2024-11-21T16:48:16 Z epicci23 Trampoline (info1cup20_trampoline) C++17
100 / 100
1260 ms 81548 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:55:11: warning: unused variable 'B' [-Wunused-variable]
   55 |       int B = ar[lift[p][i]][1];
      |           ^
# Verdict Execution time Memory Grader output
1 Correct 10 ms 2640 KB 200 token(s): yes count is 21, no count is 179
2 Correct 12 ms 2824 KB 200 token(s): yes count is 70, no count is 130
3 Correct 7 ms 2128 KB 197 token(s): yes count is 25, no count is 172
# Verdict Execution time Memory Grader output
1 Correct 346 ms 50504 KB 4000 token(s): yes count is 99, no count is 3901
2 Correct 369 ms 52296 KB 4000 token(s): yes count is 91, no count is 3909
3 Correct 359 ms 51268 KB 4000 token(s): yes count is 4000, no count is 0
4 Correct 422 ms 52560 KB 4000 token(s): yes count is 1991, no count is 2009
# Verdict Execution time Memory Grader output
1 Correct 522 ms 50516 KB 200000 token(s): yes count is 110486, no count is 89514
2 Correct 571 ms 62136 KB 200000 token(s): yes count is 114664, no count is 85336
3 Correct 539 ms 61896 KB 200000 token(s): yes count is 86232, no count is 113768
4 Correct 697 ms 62584 KB 200000 token(s): yes count is 94603, no count is 105397
5 Correct 891 ms 62484 KB 200000 token(s): yes count is 94148, no count is 105852
6 Correct 1113 ms 68264 KB 200000 token(s): yes count is 97163, no count is 102837
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1556 KB 5000 token(s): yes count is 3238, no count is 1762
2 Correct 11 ms 2032 KB 5000 token(s): yes count is 3837, no count is 1163
3 Correct 15 ms 2876 KB 5000 token(s): yes count is 4104, no count is 896
4 Correct 12 ms 1800 KB 5000 token(s): yes count is 3934, no count is 1066
5 Correct 13 ms 1924 KB 5000 token(s): yes count is 3384, no count is 1616
6 Correct 11 ms 1872 KB 5000 token(s): yes count is 3390, no count is 1610
# Verdict Execution time Memory Grader output
1 Correct 1260 ms 57844 KB 200000 token(s): yes count is 171404, no count is 28596
2 Correct 1006 ms 64380 KB 200000 token(s): yes count is 161254, no count is 38746
3 Correct 562 ms 62024 KB 200000 token(s): yes count is 117455, no count is 82545
4 Correct 1100 ms 81548 KB 200000 token(s): yes count is 182118, no count is 17882
5 Correct 706 ms 68676 KB 200000 token(s): yes count is 167565, no count is 32435
6 Correct 580 ms 62532 KB 200000 token(s): yes count is 156797, no count is 43203
7 Correct 565 ms 62488 KB 200000 token(s): yes count is 156797, no count is 43203
8 Correct 616 ms 61836 KB 200000 token(s): yes count is 122100, no count is 77900
9 Correct 1076 ms 68412 KB 200000 token(s): yes count is 139670, no count is 60330
10 Correct 1040 ms 68576 KB 200000 token(s): yes count is 165806, no count is 34194
11 Correct 1199 ms 74324 KB 200000 token(s): yes count is 175646, no count is 24354
12 Correct 532 ms 61916 KB 200000 token(s): yes count is 134695, no count is 65305
13 Correct 511 ms 62000 KB 200000 token(s): yes count is 126733, no count is 73267
14 Correct 644 ms 62536 KB 200000 token(s): yes count is 155290, no count is 44710
15 Correct 461 ms 61776 KB 200000 token(s): yes count is 129674, no count is 70326