Submission #922130

# Submission time Handle Problem Language Result Execution time Memory
922130 2024-02-05T06:02:33 Z gelastropod Trampoline (info1cup20_trampoline) C++14
100 / 100
1165 ms 108760 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

vector<vector<int>> adjlist, twok;
void dfs(int x, int p)
{
	for (int i = 0; i < 19; i++)
	{
		if (twok[i][x] == -1) break;
		twok[i + 1][x] = twok[i][twok[i][x]];
	}
	for (int i : adjlist[x])
	{
		if (i == p) continue;
		twok[0][i] = x;
		dfs(i, x);
	}
}

int kances(int x, int k)
{
	for (int i = 0; i < 20; i++)
	{
		if (x == -1) break;
		if (k & (1LL << i)) x = twok[i][x];
	}
	return x;
}

signed main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int R, C, N, T, a, b, c, d, count = 0, x;
	cin >> R >> C >> N;
	adjlist = vector<vector<int>>(N, vector<int>());
	twok = vector<vector<int>>(20, vector<int>(N, -1));
	set<int> visited;
	map<int, set<pair<int, int>>> green;
	vector<pair<int, int>> greens;
	vector<int> subroots;
	for (int i = 0; i < N; i++)
	{
		cin >> a >> b;
		a--, b--;
		swap(a, b);
		if (visited.lower_bound(b) == visited.end() || *visited.lower_bound(b) != b)
		{
			visited.insert(b);
			green[b] = set<pair<int, int>>();
		}
		green[b].insert(pair<int, int>(a, count));
		greens.push_back(pair<int, int>(a, b));
		count++;
	}
	for (auto i : green)
	{
		for (auto j : i.second)
		{
			if (visited.lower_bound(i.first + 1) == visited.end() || *visited.lower_bound(i.first + 1) != i.first + 1)
			{
				subroots.push_back(j.second);
				continue;
			}
			if (green[i.first + 1].lower_bound(pair<int, int>(j.first, 0)) == green[i.first + 1].end())
			{
				subroots.push_back(j.second);
				continue;
			}
			x = green[i.first + 1].lower_bound(pair<int, int>(j.first, 0))->second;
			adjlist[j.second].push_back(x);
			adjlist[x].push_back(j.second);
		}
	}
	for (int i : subroots) dfs(i, -1);
	cin >> T;
	for (int i = 0; i < T; i++)
	{
		cin >> a >> b >> c >> d;
		a--, b--, c--, d--;
		swap(a, b);
		swap(c, d);
		if (a > c || b > d)
		{
			cout << "No\n";
			continue;
		}
		if (b == d)
		{
			cout << "Yes\n";
			continue;
		}
		if (visited.lower_bound(b) == visited.end() || *visited.lower_bound(b) != b)
		{
			cout << "No\n";
			continue;
		}
		if (green[b].lower_bound(pair<int, int>(a, 0)) == green[b].end())
		{
			cout << "No\n";
			continue;
		}
		x = green[b].lower_bound(pair<int, int>(a, 0))->second;
		x = kances(x, d - b - 1);
		if (x == -1)
		{
			cout << "No\n";
			continue;
		}
		cout << (greens[x].first <= c ? "Yes\n" : "No\n");
	}
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 3032 KB 200 token(s): yes count is 21, no count is 179
2 Correct 8 ms 3288 KB 200 token(s): yes count is 70, no count is 130
3 Correct 6 ms 2396 KB 197 token(s): yes count is 25, no count is 172
# Verdict Execution time Memory Grader output
1 Correct 317 ms 61564 KB 4000 token(s): yes count is 99, no count is 3901
2 Correct 274 ms 61796 KB 4000 token(s): yes count is 91, no count is 3909
3 Correct 286 ms 60684 KB 4000 token(s): yes count is 4000, no count is 0
4 Correct 275 ms 61792 KB 4000 token(s): yes count is 1991, no count is 2009
# Verdict Execution time Memory Grader output
1 Correct 435 ms 78580 KB 200000 token(s): yes count is 110486, no count is 89514
2 Correct 506 ms 75000 KB 200000 token(s): yes count is 114664, no count is 85336
3 Correct 408 ms 71988 KB 200000 token(s): yes count is 86232, no count is 113768
4 Correct 529 ms 72496 KB 200000 token(s): yes count is 94603, no count is 105397
5 Correct 517 ms 72160 KB 200000 token(s): yes count is 94148, no count is 105852
6 Correct 600 ms 84356 KB 200000 token(s): yes count is 97163, no count is 102837
# Verdict Execution time Memory Grader output
1 Correct 10 ms 2136 KB 5000 token(s): yes count is 3238, no count is 1762
2 Correct 7 ms 2160 KB 5000 token(s): yes count is 3837, no count is 1163
3 Correct 12 ms 3024 KB 5000 token(s): yes count is 4104, no count is 896
4 Correct 9 ms 2292 KB 5000 token(s): yes count is 3934, no count is 1066
5 Correct 9 ms 2560 KB 5000 token(s): yes count is 3384, no count is 1616
6 Correct 7 ms 2392 KB 5000 token(s): yes count is 3390, no count is 1610
# Verdict Execution time Memory Grader output
1 Correct 1004 ms 86576 KB 200000 token(s): yes count is 171404, no count is 28596
2 Correct 912 ms 75384 KB 200000 token(s): yes count is 161254, no count is 38746
3 Correct 544 ms 72168 KB 200000 token(s): yes count is 117455, no count is 82545
4 Correct 1165 ms 108760 KB 200000 token(s): yes count is 182118, no count is 17882
5 Correct 748 ms 91268 KB 200000 token(s): yes count is 167565, no count is 32435
6 Correct 485 ms 75828 KB 200000 token(s): yes count is 156797, no count is 43203
7 Correct 586 ms 75420 KB 200000 token(s): yes count is 156797, no count is 43203
8 Correct 523 ms 72576 KB 200000 token(s): yes count is 122100, no count is 77900
9 Correct 861 ms 84388 KB 200000 token(s): yes count is 139670, no count is 60330
10 Correct 1014 ms 84172 KB 200000 token(s): yes count is 165806, no count is 34194
11 Correct 1059 ms 96440 KB 200000 token(s): yes count is 175646, no count is 24354
12 Correct 430 ms 77848 KB 200000 token(s): yes count is 134695, no count is 65305
13 Correct 391 ms 78780 KB 200000 token(s): yes count is 126733, no count is 73267
14 Correct 526 ms 72092 KB 200000 token(s): yes count is 155290, no count is 44710
15 Correct 396 ms 75408 KB 200000 token(s): yes count is 129674, no count is 70326