Submission #346800

#TimeUsernameProblemLanguageResultExecution timeMemory
346800arnold518Trampoline (info1cup20_trampoline)C++14
100 / 100
788 ms55476 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 2e5; int R, C, N, Q; pii A[MAXN+10]; unordered_map<int, vector<pii>> M; int par[MAXN+10][30]; int main() { scanf("%d%d%d", &R, &C, &N); for(int i=1; i<=N; i++) { scanf("%d%d", &A[i].first, &A[i].second); M[A[i].first].push_back({A[i].second, i}); } for(auto &it : M) { sort(it.second.begin(), it.second.end()); } for(int i=1; i<=N; i++) { if(M.find(A[i].first+1)==M.end()) continue; auto it=lower_bound(M[A[i].first+1].begin(), M[A[i].first+1].end(), pii(A[i].second, 0)); if(it==M[A[i].first+1].end()) par[i][0]=0; else par[i][0]=it->second; if(par[i][0]!=0) assert(A[par[i][0]].first==A[i].first+1); } A[0]={2e9, 2e9}; for(int i=1; i<=20; i++) for(int j=1; j<=N; j++) par[j][i]=par[par[j][i-1]][i-1]; scanf("%d", &Q); while(Q--) { int y1, x1, y2, x2; scanf("%d%d%d%d", &y1, &x1, &y2, &x2); if(x1>x2 || y1>y2) { printf("No\n"); continue; } if(y1==y2 && x1<=x2) { printf("Yes\n"); continue; } if(M.find(y1)==M.end()) { printf("No\n"); continue; } auto it=lower_bound(M[y1].begin(), M[y1].end(), pii(x1, 0)); if(it==M[y1].end()) { printf("No\n"); continue; } int now=it->second; /* while(1) { if(A[par[now][0]].first>=y2) break; now=par[now][0]; } */ for(int i=20; i>=0; i--) { if(A[par[now][i]].first<y2) now=par[now][i]; } if(A[now].first!=y2-1) { printf("No\n"); continue; } if(A[now].second<=x2) { printf("Yes\n"); } else { printf("No\n"); } } }

Compilation message (stderr)

trampoline.cpp: In function 'int main()':
trampoline.cpp:17:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   17 |  scanf("%d%d%d", &R, &C, &N);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
trampoline.cpp:20:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   20 |   scanf("%d%d", &A[i].first, &A[i].second);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
trampoline.cpp:41:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   41 |  scanf("%d", &Q);
      |  ~~~~~^~~~~~~~~~
trampoline.cpp:45:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   45 |   scanf("%d%d%d%d", &y1, &x1, &y2, &x2);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...