Submission #921353

# Submission time Handle Problem Language Result Execution time Memory
921353 2024-02-03T18:04:38 Z Ianis Trampoline (info1cup20_trampoline) C++17
54 / 100
556 ms 61820 KB
#ifdef LOCAL
#include <iostream>
#include <fstream>
#include <vector>
#include <stack>
#include <map>
#include <set>
#else
#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
#define endl '\n'
#endif

#define fi first
#define se second

#define lsb(x) (x & (-x))

using namespace std;

const int NMAX = 2e5+5;
const int LOGN = 21;

struct Point {
   int x, y;
};

int n;
Point a[NMAX];
map<int, map<int, int>> mp;
int dp[LOGN][NMAX];
int lg2[NMAX];

void read() {
   int r, c;
   cin >> r >> c >> n;
   for (int i = 1; i <= n; i++) {
      cin >> a[i].x >> a[i].y;
      mp[a[i].x][a[i].y] = i;
   }
}

void precalc() {
   for (int i = 1; i <= n; i++) {
      auto it = mp[a[i].x + 1].lower_bound(a[i].y);
      if (it != mp[a[i].x + 1].end())
         dp[0][i] = it->se;
   }

   for (int i = 2; i <= n; i++)
      lg2[i] = lg2[i >> 1] + 1;

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

int jump(int u, int k) {
   if (k == 0) return u;
   return jump(dp[lg2[lsb(k)]][u], k ^ lsb(k));
}

Point jump(int x, int y, int k) {
   auto it = mp[x].lower_bound(y);
   if (it == mp[x].end()) return { };
   return a[jump(it->se, k)];
}

bool query(int x1, int y1, int x2, int y2) {
   if (x2 < x1 || y2 < y1) return false;
   if (x1 == x2) return true;
   Point p = jump(x1, y1, x2 - x1 - 1);
   if (!p.x) return false;
   return p.y <= y2;
}

signed main() {
#ifdef LOCAL
   freopen("input.txt", "r", stdin);
#endif
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   
   read();
   precalc();

   int t = 1;
   cin >> t;

   while (t--) {
      int x1, y1, x2, y2;
      cin >> x1 >> y1 >> x2 >> y2;
      cout << (query(x1, y1, x2, y2) ? "Yes" : "No") << endl;
   }

   return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 15192 KB 200 token(s): yes count is 21, no count is 179
2 Correct 7 ms 15196 KB 200 token(s): yes count is 70, no count is 130
3 Correct 5 ms 13144 KB 197 token(s): yes count is 25, no count is 172
# Verdict Execution time Memory Grader output
1 Correct 159 ms 30504 KB 4000 token(s): yes count is 99, no count is 3901
2 Correct 190 ms 30548 KB 4000 token(s): yes count is 91, no count is 3909
3 Correct 196 ms 30264 KB 4000 token(s): yes count is 4000, no count is 0
4 Correct 156 ms 30548 KB 4000 token(s): yes count is 1991, no count is 2009
# Verdict Execution time Memory Grader output
1 Correct 254 ms 40956 KB 200000 token(s): yes count is 110486, no count is 89514
2 Correct 294 ms 40788 KB 200000 token(s): yes count is 114664, no count is 85336
3 Correct 338 ms 40900 KB 200000 token(s): yes count is 86232, no count is 113768
4 Correct 314 ms 41200 KB 200000 token(s): yes count is 94603, no count is 105397
5 Correct 348 ms 41132 KB 200000 token(s): yes count is 94148, no count is 105852
6 Correct 425 ms 47016 KB 200000 token(s): yes count is 97163, no count is 102837
# Verdict Execution time Memory Grader output
1 Correct 6 ms 13148 KB 5000 token(s): yes count is 3238, no count is 1762
2 Correct 6 ms 13148 KB 5000 token(s): yes count is 3837, no count is 1163
3 Runtime error 14 ms 23896 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 556 ms 48464 KB 200000 token(s): yes count is 171404, no count is 28596
2 Correct 455 ms 42860 KB 200000 token(s): yes count is 161254, no count is 38746
3 Runtime error 181 ms 61820 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -