답안 #639159

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
639159 2022-09-08T18:35:27 Z Dec0Dedd Trampoline (info1cup20_trampoline) C++14
100 / 100
1143 ms 82400 KB
#include <bits/stdc++.h>

using namespace std;

#define pii pair<int, int>
#define pp pair<pii, int>

const int N = 2e5+10;
const int K = 20;

vector<int> G[N];
pii p[N];
set<pii> s[N];

int r, c, n, indeg[N], up[N][K+1];

void dfs(int v, int p) {
   up[v][0]=p;
   for (int i=1; i<=K; ++i) up[v][i]=up[up[v][i-1]][i-1];

   for (auto u : G[v]) {
      if (u == p) continue;
      dfs(u, v);
   }
}

int fv(int i, int x) {
   for (int k=K; k>=0; --k) {
      int idx=up[i][k];
      if (p[idx].first < x) i=idx;
   }
   return i;
} 

void solve() {
   ios_base::sync_with_stdio(0);
   cin.tie(NULL);
   cout.tie(NULL);
   
   cin>>r>>c>>n;

   set<int> st;
   map<int, int> sc;
   for (int i=1; i<=n; ++i) {
      int a, b; cin>>a>>b;
      p[i]={a, b};
      st.insert(a);
   }

   int i=1;
   for (auto u : st) sc[u]=i++;
   for (int i=1; i<=n; ++i) s[sc[p[i].first]].insert({p[i].second, i});

   for (int i=1; i<=n; ++i) {
      int a=p[i].first, b=p[i].second;
      if (sc.find(a+1) == sc.end()) continue;

      int nxt=sc[a+1];
      a=sc[a];
      auto ptr=s[nxt].lower_bound({b, -1});

      if (ptr == s[nxt].end()) continue;
      G[ptr->second].push_back(i);
      ++indeg[i];
   }

   for (int i=1; i<=n; ++i) {
      if (indeg[i] == 0) dfs(i, i);
   }

   int q; cin>>q;
   for (int i=1; i<=q; ++i) {
      int is, js, ie, je;
      cin>>is>>js>>ie>>je;

      if (js > je) cout<<"No\n";
      else if (is == ie) cout<<"Yes\n";
      else {
         if (sc.find(is) == sc.end()) {
            cout<<"No\n";
            continue;
         }

         is=sc[is];
         auto ptr=s[is].lower_bound({js, -1});

         if (ptr == s[is].end()) {
            cout<<"No\n";
            continue;
         }
         int f=fv(ptr->second, ie);

         if (p[f].first == ie-1 && p[f].second <= je) cout<<"Yes\n";
         else cout<<"No\n";
      }
   }

   for (int i=1; i<=n; ++i) s[i].clear(), G[i].clear(), indeg[i]=0;
}

int main() {
   solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 15844 KB 200 token(s): yes count is 21, no count is 179
2 Correct 14 ms 16084 KB 200 token(s): yes count is 70, no count is 130
3 Correct 14 ms 15572 KB 197 token(s): yes count is 25, no count is 172
# 결과 실행 시간 메모리 Grader output
1 Correct 346 ms 46192 KB 4000 token(s): yes count is 99, no count is 3901
2 Correct 335 ms 47948 KB 4000 token(s): yes count is 91, no count is 3909
3 Correct 333 ms 49428 KB 4000 token(s): yes count is 4000, no count is 0
4 Correct 368 ms 48004 KB 4000 token(s): yes count is 1991, no count is 2009
# 결과 실행 시간 메모리 Grader output
1 Correct 437 ms 50132 KB 200000 token(s): yes count is 110486, no count is 89514
2 Correct 497 ms 51580 KB 200000 token(s): yes count is 114664, no count is 85336
3 Correct 536 ms 51680 KB 200000 token(s): yes count is 86232, no count is 113768
4 Correct 602 ms 52812 KB 200000 token(s): yes count is 94603, no count is 105397
5 Correct 627 ms 52768 KB 200000 token(s): yes count is 94148, no count is 105852
6 Correct 766 ms 61532 KB 200000 token(s): yes count is 97163, no count is 102837
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 15488 KB 5000 token(s): yes count is 3238, no count is 1762
2 Correct 15 ms 15444 KB 5000 token(s): yes count is 3837, no count is 1163
3 Correct 15 ms 15912 KB 5000 token(s): yes count is 4104, no count is 896
4 Correct 14 ms 15468 KB 5000 token(s): yes count is 3934, no count is 1066
5 Correct 15 ms 15760 KB 5000 token(s): yes count is 3384, no count is 1616
6 Correct 13 ms 15444 KB 5000 token(s): yes count is 3390, no count is 1610
# 결과 실행 시간 메모리 Grader output
1 Correct 947 ms 64224 KB 200000 token(s): yes count is 171404, no count is 28596
2 Correct 794 ms 55420 KB 200000 token(s): yes count is 161254, no count is 38746
3 Correct 542 ms 51684 KB 200000 token(s): yes count is 117455, no count is 82545
4 Correct 1117 ms 82400 KB 200000 token(s): yes count is 182118, no count is 17882
5 Correct 750 ms 61128 KB 200000 token(s): yes count is 167565, no count is 32435
6 Correct 557 ms 51012 KB 200000 token(s): yes count is 156797, no count is 43203
7 Correct 595 ms 50980 KB 200000 token(s): yes count is 156797, no count is 43203
8 Correct 537 ms 50724 KB 200000 token(s): yes count is 122100, no count is 77900
9 Correct 1095 ms 59660 KB 200000 token(s): yes count is 139670, no count is 60330
10 Correct 1143 ms 59764 KB 200000 token(s): yes count is 165806, no count is 34194
11 Correct 1044 ms 68208 KB 200000 token(s): yes count is 175646, no count is 24354
12 Correct 410 ms 45888 KB 200000 token(s): yes count is 134695, no count is 65305
13 Correct 435 ms 46300 KB 200000 token(s): yes count is 126733, no count is 73267
14 Correct 634 ms 47892 KB 200000 token(s): yes count is 155290, no count is 44710
15 Correct 483 ms 46488 KB 200000 token(s): yes count is 129674, no count is 70326