Submission #639158

# Submission time Handle Problem Language Result Execution time Memory
639158 2022-09-08T18:34:38 Z Dec0Dedd Trampoline (info1cup20_trampoline) C++14
100 / 100
1718 ms 89292 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() {
   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();
}
# Verdict Execution time Memory Grader output
1 Correct 16 ms 15700 KB 200 token(s): yes count is 21, no count is 179
2 Correct 19 ms 16084 KB 200 token(s): yes count is 70, no count is 130
3 Correct 17 ms 15564 KB 197 token(s): yes count is 25, no count is 172
# Verdict Execution time Memory Grader output
1 Correct 411 ms 46016 KB 4000 token(s): yes count is 99, no count is 3901
2 Correct 413 ms 47916 KB 4000 token(s): yes count is 91, no count is 3909
3 Correct 392 ms 49524 KB 4000 token(s): yes count is 4000, no count is 0
4 Correct 409 ms 48032 KB 4000 token(s): yes count is 1991, no count is 2009
# Verdict Execution time Memory Grader output
1 Correct 997 ms 56456 KB 200000 token(s): yes count is 110486, no count is 89514
2 Correct 1062 ms 58096 KB 200000 token(s): yes count is 114664, no count is 85336
3 Correct 1109 ms 58184 KB 200000 token(s): yes count is 86232, no count is 113768
4 Correct 1210 ms 59208 KB 200000 token(s): yes count is 94603, no count is 105397
5 Correct 1170 ms 59244 KB 200000 token(s): yes count is 94148, no count is 105852
6 Correct 1344 ms 67644 KB 200000 token(s): yes count is 97163, no count is 102837
# Verdict Execution time Memory Grader output
1 Correct 28 ms 15464 KB 5000 token(s): yes count is 3238, no count is 1762
2 Correct 32 ms 15572 KB 5000 token(s): yes count is 3837, no count is 1163
3 Correct 30 ms 15896 KB 5000 token(s): yes count is 4104, no count is 896
4 Correct 27 ms 15508 KB 5000 token(s): yes count is 3934, no count is 1066
5 Correct 34 ms 15728 KB 5000 token(s): yes count is 3384, no count is 1616
6 Correct 27 ms 15444 KB 5000 token(s): yes count is 3390, no count is 1610
# Verdict Execution time Memory Grader output
1 Correct 1500 ms 70440 KB 200000 token(s): yes count is 171404, no count is 28596
2 Correct 1485 ms 61880 KB 200000 token(s): yes count is 161254, no count is 38746
3 Correct 1267 ms 58368 KB 200000 token(s): yes count is 117455, no count is 82545
4 Correct 1718 ms 89292 KB 200000 token(s): yes count is 182118, no count is 17882
5 Correct 1289 ms 68156 KB 200000 token(s): yes count is 167565, no count is 32435
6 Correct 1136 ms 58268 KB 200000 token(s): yes count is 156797, no count is 43203
7 Correct 1111 ms 58168 KB 200000 token(s): yes count is 156797, no count is 43203
8 Correct 1111 ms 58260 KB 200000 token(s): yes count is 122100, no count is 77900
9 Correct 1503 ms 67792 KB 200000 token(s): yes count is 139670, no count is 60330
10 Correct 1484 ms 68568 KB 200000 token(s): yes count is 165806, no count is 34194
11 Correct 1639 ms 78364 KB 200000 token(s): yes count is 175646, no count is 24354
12 Correct 948 ms 56348 KB 200000 token(s): yes count is 134695, no count is 65305
13 Correct 995 ms 56620 KB 200000 token(s): yes count is 126733, no count is 73267
14 Correct 1182 ms 59168 KB 200000 token(s): yes count is 155290, no count is 44710
15 Correct 1034 ms 58088 KB 200000 token(s): yes count is 129674, no count is 70326