Submission #426838

# Submission time Handle Problem Language Result Execution time Memory
426838 2021-06-14T10:21:38 Z pavement Trampoline (info1cup20_trampoline) C++17
11 / 100
1076 ms 73672 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
#define int long long
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define g0(a) get<0>(a)
#define g1(a) get<1>(a)
#define g2(a) get<2>(a)
#define g3(a) get<3>(a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef double db;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int R, C, N, T, idx, r1, c1, r2, c2, a[200005], b[200005], anc[200005][25];
bool in[200005];
vector<int> adj[200005];
map<ii, int> _lab;
map<int, vector<int> > vec;

inline int lab(int a, int b) {
	return _lab[mp(a, b)];
}

void dfs(int n, int e = -1) {
	anc[n][0] = e;
	for (int i = 1; i <= 20; i++)
		if (anc[n][i - 1] != -1) anc[n][i] = anc[anc[n][i - 1]][i - 1];
	for (auto u : adj[n]) if (u != e) dfs(u, n);
}

main() {
	memset(anc, -1, sizeof anc);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> R >> C >> N;
	for (int i = 1; i <= N; i++) {
		cin >> a[i] >> b[i];
		vec[a[i]].pb(b[i]);
		_lab[mp(a[i], b[i])] = ++idx;
	}
	for (auto &i : vec) {
		sort(i.second.begin(), i.second.end());
		for (int j : i.second) {
			auto tmp = lower_bound(vec[i.first + 1].begin(), vec[i.first + 1].end(), j);
			if (tmp != vec[i.first + 1].end()) {
				adj[lab(i.first + 1, *tmp)].pb(lab(i.first, j));
				in[lab(i.first, j)] = 1;
			}
		}
	}
	for (int i = 1; i <= N; i++) {
		if (!in[i]) dfs(i);
	}
	cin >> T;
	while (T--) {
		cin >> r1 >> c1 >> r2 >> c2;
		if (r1 > r2) cout << "No\n";
		else if (r1 == r2) cout << "Yes\n";
		else {
			auto tmp = lower_bound(vec[r1].begin(), vec[r1].end(), c1);
			if (tmp != vec[r1].end()) {
				int curr = lab(r1, *tmp), up = 0;
				for (int i = 20; i >= 0; i--)
					if (anc[curr][i] != -1 && up + (1 << i) < r2 - r1) {
						curr = anc[curr][i];
						up += (1 << i);
					}
				if (a[curr] == r2 - 1 && b[curr] <= c2) cout << "Yes\n";
				else cout << "No\n";
			} else cout << "No\n";
		}
	}
}

Compilation message

trampoline.cpp:45:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   45 | main() {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 45028 KB expected YES, found NO [1st token]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 365 ms 64908 KB expected YES, found NO [3rd token]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 659 ms 63424 KB 200000 token(s): yes count is 110486, no count is 89514
2 Correct 753 ms 64112 KB 200000 token(s): yes count is 114664, no count is 85336
3 Correct 702 ms 64512 KB 200000 token(s): yes count is 86232, no count is 113768
4 Correct 832 ms 65236 KB 200000 token(s): yes count is 94603, no count is 105397
5 Correct 808 ms 65148 KB 200000 token(s): yes count is 94148, no count is 105852
6 Correct 953 ms 71552 KB 200000 token(s): yes count is 97163, no count is 102837
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 44640 KB expected YES, found NO [1st token]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1076 ms 73672 KB expected YES, found NO [1st token]
2 Halted 0 ms 0 KB -